import supervision as sv import gradio as gr from ultralytics import YOLO import sahi import numpy as np # Images sahi.utils.file.download_from_url( "https://transform.roboflow.com/bViBvBXkjUWzz4lYXwtoVTE2gpO2/210fe71d15bb416b0dfde415686da572/thumb.jpg", "wh1.jpg", ) sahi.utils.file.download_from_url( "https://transform.roboflow.com/bViBvBXkjUWzz4lYXwtoVTE2gpO2/6731f1ac3e966e90ccc0057c86b42c74/thumb.jpg", "wh2.jpg", ) sahi.utils.file.download_from_url( "https://transform.roboflow.com/bViBvBXkjUWzz4lYXwtoVTE2gpO2/ba9fc3cc24849c0408d5e2ddd4a4a4ed/thumb.jpg", "wh3.jpg", ) annotatorbbox = sv.BoxAnnotator() annotatormask=sv.MaskAnnotator() def yolov8_inference( image: gr.inputs.Image = None, conf_threshold: gr.inputs.Slider = 0.25, iou_threshold: gr.inputs.Slider = 0.45, ): image=image[:, :, ::-1].astype(np.uint8) model = YOLO("https://huggingface.co/spaces/devisionx/Fourth_demo/blob/main/best.pt") results = model(image,imgsz=640)[0] image=image[:, :, ::-1].astype(np.uint8) detections = sv.Detections.from_yolov8(results) annotated_image = annotatorbbox.annotate(scene=image, detections=detections) return annotated_image image_input = gr.inputs.Image() # Adjust the shape according to your requirements inputs = [ gr.inputs.Image(label="Input Image"), gr.Slider( minimum=0.0, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold" ), gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"), ] outputs = gr.Image(type="filepath", label="Output Image") title = "Ultralytics YOLOv8 Segmentation Demo" import os examples = [ ["wh1.jpg", 0.6, 0.45], ["wh2.jpg", 0.25, 0.45], ["wh3.jpg", 0.25, 0.45], ] demo_app = gr.Interface(examples=examples, fn=yolov8_inference, inputs=inputs, outputs=outputs, title=title, cache_examples=True, theme="default", ) demo_app.launch(debug=False, enable_queue=True)