File size: 2,071 Bytes
cc7179a
 
 
 
c75d65a
cc7179a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c75d65a
cc7179a
 
 
c75d65a
e8d8961
c75d65a
 
cc7179a
c75d65a
 
cc7179a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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/aHClLv0V9gWdgkEi3TZOcyGv4zZ2/2b24b3f5ef9330424b9fda06ad38f98a/thumb.jpg",
    "m1.jpg",
)
sahi.utils.file.download_from_url(
    "https://transform.roboflow.com/aHClLv0V9gWdgkEi3TZOcyGv4zZ2/751a6fca76be162856174c24048b293d/thumb.jpg",
    "m2.jpg",
)
sahi.utils.file.download_from_url(
    "https://transform.roboflow.com/aHClLv0V9gWdgkEi3TZOcyGv4zZ2/9373f5662c0ea03977182aa9ebe37695/thumb.jpg",
    "m3.jpg",
)




annotatorbbox = sv.BoxAnnotator()
annotatormask=sv.MaskAnnotator()

def yolov8_inference(
    image: gr.inputs.Image = None,
    conf_threshold: gr.inputs.Slider = 0.5,
    iou_threshold: gr.inputs.Slider = 0.45,
):

    image=image[:, :, ::-1].astype(np.uint8)
    model = YOLO("https://huggingface.co/spaces/devisionx/Final_demo/blob/main/best_weights.pt")
    results = model(image,imgsz=360)[0]
    image=image[:, :, ::-1].astype(np.uint8)
    detections = sv.Detections.from_yolov8(results)
    annotated_image = annotatormask.annotate(scene=image, detections=detections)
    annotated_image = annotatorbbox.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 = [
    ["m1.jpg", 0.6, 0.45],
    ["m2.jpg", 0.25, 0.45],
    ["m3.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)