Spaces:
Sleeping
Sleeping
| import supervision as sv | |
| import gradio as gr | |
| from ultralytics import YOLO | |
| import sahi | |
| sahi.utils.file.download_from_url( | |
| "https://raw.githubusercontent.com/mensss/vvvvv/main/download_14.png", | |
| "tu2.png", | |
| ) | |
| sahi.utils.file.download_from_url( | |
| "https://raw.githubusercontent.com/mensss/vvvvv/main/e7d86208-a7e1-4d2a-963c-af6102430b0c%20(1).jpg", | |
| "tu3.jpg", | |
| ) | |
| annotatorbbox = sv.BoxAnnotator() | |
| annotatormask=sv.MaskAnnotator() | |
| def yolov8_inference( | |
| image: gr.inputs.Image = None, | |
| model_name: gr.inputs.Dropdown = None, | |
| image_size: gr.inputs.Slider = 1280, | |
| conf_threshold: gr.inputs.Slider = 0.25, | |
| iou_threshold: gr.inputs.Slider = 0.45, | |
| ): | |
| model = YOLO("https://huggingface.co/spaces/devisionx/Amazon_demo/blob/main/amazon.pt") | |
| results = model(image,conf=conf_threshold,iou=iou_threshold ,imgsz=1280)[0] | |
| detections = sv.Detections.from_yolov8(results) | |
| annotated_image = annotatorbbox.annotate(scene=image, detections=detections) | |
| annotated_image = annotatormask.annotate(scene=annotated_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 = [ | |
| ["tu2.png", 0.25, 0.45], | |
| ["tu3.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) |