File size: 3,182 Bytes
0f1bb12
 
 
 
4d26a0d
0f1bb12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d26a0d
 
0f1bb12
 
 
 
 
 
 
 
 
 
 
4d26a0d
 
6ac1fcf
f7a089e
4d26a0d
0f1bb12
 
 
 
 
 
 
35eddcc
 
 
 
 
 
 
 
 
 
 
 
0f1bb12
 
 
 
 
 
35eddcc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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/zZuu207UOVOOJKuuCpmV/3512b3839afacecec643949bef398e99/thumb.jpg",
    "tu1.jpg",
)
sahi.utils.file.download_from_url(
    "https://transform.roboflow.com/zZuu207UOVOOJKuuCpmV/5b8b940fae2f9e4952395bcced0688aa/thumb.jpg",
    "tu2.jpg",
)
sahi.utils.file.download_from_url(
    "https://transform.roboflow.com/zZuu207UOVOOJKuuCpmV/347e10ab7aa2b399ec546f2037d8c786/thumb.jpg",
    "tu3.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/Fifth_demo/blob/main/best_weigh.pt")
    results = model(image,imgsz=360)[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 = "Brain Tumor Demo"
import os
examples = [
    ["tu1.jpg", 0.6, 0.45],
    ["tu2.jpg", 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)
gr.Examples(examples) # Add the examples to the app
with gr.Blocks() as demo:
    gr.Markdown(
            """
            # Tuba Brain Tumor Demo

            [Tuba](https://Tuba.ai)
            """
        )
    # Define the input components and add them to the layout
    with gr.Row():
        image_input = gr.inputs.Image()
        
        
        outputs = gr.Image(type="filepath", label="Output Image")
        
    # Define the output component and add it to the layout
    with gr.Row():
        conf_slider=gr.Slider(minimum=0.0, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold" )
    with gr.Row():
        IOU_Slider=gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold")
    
    gr.Examples(examples) # Add the examples to 

    with gr.Row():
        button = gr.Button("Run")
        
    # Define the event listener that connects the input and output components and triggers the function
    button.click(fn=get_results, inputs=[image_input, conf_slider,IOU_Slider], outputs=output, api_name="yolov8_inference")
    # Add the description below the layout
    gr.Markdown(description_html)
# Launch the app
demo.launch(share=False)