Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
from app_utils import annotate_planogram_compliance, do_sorting, xml_to_csv
|
6 |
+
from inference import run
|
7 |
+
import json
|
8 |
+
import os
|
9 |
+
from tempfile import NamedTemporaryFile
|
10 |
+
|
11 |
+
|
12 |
+
# Target names list
|
13 |
+
target_names = [
|
14 |
+
"Bottle,100PLUS ACTIVE 1.5L",
|
15 |
+
"Bottle,100PLUS ACTIVE 500ML",
|
16 |
+
"Bottle,100PLUS LEMON LIME 1.5L",
|
17 |
+
# Add all other target names here
|
18 |
+
]
|
19 |
+
|
20 |
+
# Define the function to run planogram compliance check
|
21 |
+
def planogram_compliance_check(planogram_image, master_planogram_image, annotation_file):
|
22 |
+
# Convert uploaded images to numpy arrays
|
23 |
+
planogram_img = np.array(planogram_image)
|
24 |
+
master_planogram_img = np.array(master_planogram_image)
|
25 |
+
|
26 |
+
# Perform inference on planogram image
|
27 |
+
result_list = run(
|
28 |
+
weights="base_line_best_model_exp5.pt",
|
29 |
+
source=planogram_img,
|
30 |
+
imgsz=[640, 640],
|
31 |
+
conf_thres=0.6,
|
32 |
+
iou_thres=0.6,
|
33 |
+
)
|
34 |
+
|
35 |
+
# Load annotation file and convert to DataFrame
|
36 |
+
if annotation_file is not None:
|
37 |
+
annotation_df = xml_to_csv(annotation_file)
|
38 |
+
sorted_xml_df = do_sorting(annotation_df)
|
39 |
+
else:
|
40 |
+
sorted_xml_df = None
|
41 |
+
|
42 |
+
# Run planogram compliance check
|
43 |
+
compliance_score, annotated_image = run_compliance_check(
|
44 |
+
planogram_img, master_planogram_img, sorted_xml_df, result_list
|
45 |
+
)
|
46 |
+
|
47 |
+
return compliance_score, annotated_image
|
48 |
+
|
49 |
+
# Define the function to run planogram compliance check
|
50 |
+
def run_compliance_check(planogram_img, master_planogram_img, sorted_xml_df, result_list):
|
51 |
+
# Perform further processing and calculation of compliance score
|
52 |
+
compliance_score = 0.0 # Placeholder for actual score calculation
|
53 |
+
annotated_image = None # Placeholder for annotated image
|
54 |
+
|
55 |
+
# Your compliance score calculation and image annotation logic here
|
56 |
+
|
57 |
+
return compliance_score, annotated_image
|
58 |
+
|
59 |
+
# Gradio interface
|
60 |
+
planogram_check_interface = gr.Interface(
|
61 |
+
fn=planogram_compliance_check,
|
62 |
+
inputs=[
|
63 |
+
gr.inputs.Image(label="Planogram Image"),
|
64 |
+
gr.inputs.Image(label="Master Planogram Image"),
|
65 |
+
gr.inputs.Dataframe(label="Annotation File (XML)")
|
66 |
+
],
|
67 |
+
outputs=[
|
68 |
+
gr.outputs.Textbox(label="Compliance Score"),
|
69 |
+
gr.outputs.Image(label="Annotated Planogram Image"),
|
70 |
+
],
|
71 |
+
title="Planogram Compliance Checker",
|
72 |
+
description="Upload planogram image, master planogram image, and annotation file (if available) to check compliance."
|
73 |
+
)
|
74 |
+
|
75 |
+
# Launch the interface
|
76 |
+
planogram_check_interface.launch()
|