import gradio as gr import numpy as np import pandas as pd from app_utils import annotate_planogram_compliance, do_sorting, xml_to_csv from inference import run import json import os from tempfile import NamedTemporaryFile # Target names list target_names = [ "Bottle,100PLUS ACTIVE 1.5L", "Bottle,100PLUS ACTIVE 500ML", "Bottle,100PLUS LEMON LIME 1.5L", # Add all other target names here ] # Define the function to run planogram compliance check def planogram_compliance_check(planogram_image, master_planogram_image, annotation_file): # Convert uploaded images to numpy arrays planogram_img = np.array(planogram_image) master_planogram_img = np.array(master_planogram_image) # Perform inference on planogram image result_list = run( weights="base_line_best_model_exp5.pt", source=planogram_img, imgsz=[640, 640], conf_thres=0.6, iou_thres=0.6, ) # Load annotation file and convert to DataFrame if annotation_file is not None: annotation_df = xml_to_csv(annotation_file) sorted_xml_df = do_sorting(annotation_df) else: sorted_xml_df = None # Run planogram compliance check compliance_score, annotated_image = run_compliance_check( planogram_img, master_planogram_img, sorted_xml_df, result_list ) return compliance_score, annotated_image # Define the function to run planogram compliance check def run_compliance_check(planogram_img, master_planogram_img, sorted_xml_df, result_list): # Perform further processing and calculation of compliance score compliance_score = 0.0 # Placeholder for actual score calculation annotated_image = None # Placeholder for annotated image # Your compliance score calculation and image annotation logic here return compliance_score, annotated_image # Gradio interface planogram_check_interface = gr.Interface( fn=planogram_compliance_check, inputs=[ gr.inputs.Image(label="Planogram Image"), gr.inputs.Image(label="Master Planogram Image"), gr.inputs.Dataframe(label="Annotation File (XML)") ], outputs=[ gr.outputs.Textbox(label="Compliance Score"), gr.outputs.Image(label="Annotated Planogram Image"), ], title="Planogram Compliance Checker", description="Upload planogram image, master planogram image, and annotation file (if available) to check compliance." ) # Launch the interface planogram_check_interface.launch()