CoolFace
Apppublic

Aalaa/Visual_Pollution_detection

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py69 linesDownload Raw Back to root
1import gradio as gr2import yolov73import subprocess4import tempfile5import time6from pathlib import Path7import uuid8import cv29import gradio as gr10 11 12    13def image_fn(14    image: gr.inputs.Image = None,15    model_path: gr.inputs.Dropdown = None,16    image_size: gr.inputs.Slider = 640,17    conf_threshold: gr.inputs.Slider = 0.25,18    iou_threshold: gr.inputs.Slider = 0.45,19):20    """21    YOLOv7 inference function22    Args:23        image: Input image24        model_path: Path to the model25        image_size: Image size26        conf_threshold: Confidence threshold27        iou_threshold: IOU threshold28    Returns:29        Rendered image30    """31 32    model = yolov7.load(model_path, device="cpu", hf_model=True, trace=False)33    model.conf = conf_threshold34    model.iou = iou_threshold35    results = model([image], size=image_size)36    return results.render()[0]37  38  39        40 41image_interface = gr.Interface(42    fn=image_fn,43    inputs=[44    gr.inputs.Image(type="pil", label="Input Image"),45    gr.inputs.Dropdown(46        choices=[47            "Aalaa/Yolov7_Visual_Pollution_Detection",48        ],49        default="Aalaa/Yolov7_Visual_Pollution_Detection",50        label="Model",51    )52    #gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size")53    #gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),54    #gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold")55],56    outputs=gr.outputs.Image(type="filepath", label="Output Image"),57    58    examples=[['image1.jpg', 'Aalaa/Yolov7_Visual_Pollution_Detection', 640, 0.25, 0.45]],59    cache_examples=True,60    theme='huggingface',61)62 63 64 65if __name__ == "__main__":66    gr.TabbedInterface(67        [image_interface],68        ["Run on Images"],69    ).launch()