Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,54 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
-
from models import Reciept_Analyzer
|
| 4 |
-
from utils import find_product
|
| 5 |
-
import os
|
| 6 |
-
model = Reciept_Analyzer()
|
| 7 |
-
|
| 8 |
-
sample_images = []
|
| 9 |
-
for img_file in os.listdir("samples/"):
|
| 10 |
-
sample_images.append(os.path.join("samples", img_file))
|
| 11 |
-
|
| 12 |
-
def predict(image):
|
| 13 |
-
results = model.forward(image)
|
| 14 |
-
return results
|
| 15 |
-
|
| 16 |
-
def handle_input(image, item_name):
|
| 17 |
-
df = predict(image) # Phân tích hóa đơn và trả về dataframe
|
| 18 |
-
print(df)
|
| 19 |
-
result = find_product(item_name, df)
|
| 20 |
-
return result
|
| 21 |
-
|
| 22 |
-
# Thiết kế giao diện với Gradio
|
| 23 |
-
def create_interface():
|
| 24 |
-
with gr.Blocks() as app:
|
| 25 |
-
gr.Markdown(f"# Ứng dụng phân tích hóa đơn siêu thị")
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
with gr.Row():
|
| 29 |
-
# Cột bên trái
|
| 30 |
-
with gr.Column():
|
| 31 |
-
gr.Markdown("### Tải lên hóa đơn hoặc chọn ảnh mẫu")
|
| 32 |
-
image_input = gr.Image(label="Ảnh hóa đơn", type="filepath")
|
| 33 |
-
|
| 34 |
-
gr.Markdown("### Ảnh mẫu")
|
| 35 |
-
example = gr.Examples(
|
| 36 |
-
inputs=image_input,
|
| 37 |
-
examples=sample_images
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
# Cột bên phải
|
| 41 |
-
with gr.Column():
|
| 42 |
-
gr.Markdown("### Tìm kiếm thông tin item")
|
| 43 |
-
item_input = gr.Textbox(label="Tên item cần tìm")
|
| 44 |
-
output = gr.Textbox(label="Kết quả")
|
| 45 |
-
|
| 46 |
-
search_button = gr.Button("Tìm kiếm")
|
| 47 |
-
search_button.click(fn=handle_input, inputs=[image_input, item_input], outputs=output)
|
| 48 |
-
|
| 49 |
-
return app
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
# Chạy ứng dụng
|
| 53 |
-
app = create_interface()
|
| 54 |
-
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|