|
import gradio as gr |
|
import cv2 |
|
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 = [ |
|
"Bottle,100PLUS ACTIVE 1.5L", |
|
"Bottle,100PLUS ACTIVE 500ML", |
|
"Bottle,100PLUS LEMON LIME 1.5L", |
|
|
|
] |
|
|
|
|
|
def planogram_compliance_check(planogram_image, master_planogram_image, annotation_file): |
|
|
|
planogram_img = np.array(planogram_image) |
|
master_planogram_img = np.array(master_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, |
|
) |
|
|
|
|
|
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 |
|
|
|
|
|
compliance_score, annotated_image = run_compliance_check( |
|
planogram_img, master_planogram_img, sorted_xml_df, result_list |
|
) |
|
|
|
return compliance_score, annotated_image |
|
|
|
|
|
def run_compliance_check(planogram_img, master_planogram_img, sorted_xml_df, result_list): |
|
|
|
compliance_score = 0.0 |
|
annotated_image = None |
|
|
|
|
|
|
|
return compliance_score, annotated_image |
|
|
|
|
|
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." |
|
) |
|
|
|
|
|
planogram_check_interface.launch() |
|
|