import torch import gradio as gr from huggingface_hub import hf_hub_download from PIL import Image REPO_ID = "thoucentric/Shelf_Objects_Detection_Yolov7_Pytorch" FILENAME = "best.pt" yolov7_custom_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME) model = torch.hub.load('Owaiskhan9654/yolov7-1:main',model='custom', path_or_model=yolov7_custom_weights, force_reload=True) # Github repository https://github.com/Owaiskhan9654 def object_detection(image: gr.inputs.Image = None): results = model(image) results.render() count_dict = results.pandas().xyxy[0]['name'].value_counts().to_dict() if len(count_dict)>0: return Image.fromarray(results.imgs[0]),str(count_dict) else: return Image.fromarray(results.imgs[0]),'No object Found. Add more Custom classes in the training set' title = "Yolov7 Custom" # image = gr.inputs.Image(shape=(640, 640), image_mode="RGB", source="upload", label="Upload Image", optional=False) inputs = gr.inputs.Image(shape=(640, 640), image_mode="RGB", source="upload", label="Upload Image", optional=False) # gr.inputs.Dropdown(["best.pt",], # default="best.pt", label="Model"), # gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"), # gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"), # gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"), # ] outputs = gr.outputs.Image(type="pil", label="Output Image") outputs_cls = gr.Label(label= "Categories Detected Proportion Statistics" ) Custom_description="