openvision commited on
Commit
fc9e3e8
·
verified ·
1 Parent(s): f6ed50f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -2
app.py CHANGED
@@ -4,8 +4,6 @@ from PIL import Image
4
  from ultralytics import ASSETS, YOLO
5
  from ultralytics.utils.downloads import safe_download
6
  from huggingface_hub import hf_hub_download
7
- import os
8
- os.environ["YOLO_CONFIG_DIR"] = "/tmp/Ultralytics"
9
 
10
  # Download OBB test image if not exists
11
  OBB_IMAGE = ASSETS.parent / "boats.jpg"
@@ -78,3 +76,80 @@ def predict_yoloe26(image, model_name, classes_text, conf, retina):
78
  )
79
 
80
  return Image.fromarray(results[0].plot()[..., ::-1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  from ultralytics import ASSETS, YOLO
5
  from ultralytics.utils.downloads import safe_download
6
  from huggingface_hub import hf_hub_download
 
 
7
 
8
  # Download OBB test image if not exists
9
  OBB_IMAGE = ASSETS.parent / "boats.jpg"
 
76
  )
77
 
78
  return Image.fromarray(results[0].plot()[..., ::-1])
79
+
80
+
81
+ with gr.Blocks(title="Ultralytics YOLO26 & YOLOE26 Demo") as demo:
82
+ gr.Markdown(
83
+ "# 🚀 Ultralytics YOLO26 & YOLOE26 Demo\n"
84
+ "Showcasing YOLO26 tasks and YOLOE26 open-vocabulary detection. "
85
+ "[GitHub](https://github.com/ultralytics/ultralytics) | [Docs](https://docs.ultralytics.com/models/yolo26/)"
86
+ )
87
+
88
+ with gr.Tabs():
89
+ with gr.Tab("YOLO26 Tasks"):
90
+ gr.Markdown("### Ultralytics YOLO26: Detection, Segmentation, Pose, OBB, Classification")
91
+ with gr.Row():
92
+ with gr.Column():
93
+ y26_image = gr.Image(type="pil", label="Upload Image")
94
+ with gr.Row():
95
+ y26_model = gr.Dropdown(["YOLO26-N", "YOLO26-S", "YOLO26-M", "YOLO26-L", "YOLO26-X"], label="Model")
96
+ y26_task = gr.Dropdown(list(TASK_SUFFIX.keys()), label="Task")
97
+ with gr.Accordion("Advanced Settings", open=False):
98
+ y26_conf = gr.Slider(0, 1, label="Confidence Threshold")
99
+ y26_iou = gr.Slider(0, 1, label="IoU Threshold")
100
+ y26_retina = gr.Checkbox(label="Retina Masks", info="Higher quality masks, slower inference")
101
+ y26_btn = gr.Button("Run Inference", variant="primary")
102
+ with gr.Column():
103
+ y26_output = gr.Image(type="pil", label="Result")
104
+ y26_label = gr.Label(label="Classification Results", visible=False)
105
+
106
+ y26_task.change(
107
+ lambda t: (gr.update(visible=t != "Classification"), gr.update(visible=t == "Classification")),
108
+ y26_task,
109
+ [y26_output, y26_label],
110
+ )
111
+ gr.Examples(
112
+ examples=[
113
+ [str(ASSETS / "bus.jpg"), "YOLO26-M", "Detection", 0.25, 0.45, True],
114
+ [str(ASSETS / "bus.jpg"), "YOLO26-M", "Segmentation", 0.25, 0.45, True],
115
+ [str(ASSETS / "zidane.jpg"), "YOLO26-M", "Pose", 0.25, 0.45, True],
116
+ [str(OBB_IMAGE), "YOLO26-M", "OBB", 0.25, 0.45, True],
117
+ ],
118
+ inputs=[y26_image, y26_model, y26_task, y26_conf, y26_iou, y26_retina],
119
+ outputs=[y26_output, y26_label],
120
+ fn=predict_yolo26,
121
+ cache_examples=True,
122
+ )
123
+ y26_btn.click(predict_yolo26, [y26_image, y26_model, y26_task, y26_conf, y26_iou, y26_retina], [y26_output, y26_label])
124
+
125
+ with gr.Tab("YOLOE26 Open-Vocabulary"):
126
+ gr.Markdown("### Ultralytics YOLOE26: Open-Vocabulary Segmentation - Detect any object by text description")
127
+ with gr.Row():
128
+ with gr.Column():
129
+ ye_image = gr.Image(type="pil", label="Upload Image", value=str(ASSETS / "bus.jpg"))
130
+ with gr.Row():
131
+ ye_model = gr.Dropdown(
132
+ ["YOLOE-26N", "YOLOE-26S", "YOLOE-26M", "YOLOE-26L", "YOLOE-26X"], value="YOLOE-26L", label="Model"
133
+ )
134
+ ye_classes = gr.Textbox(value="person, bus, car", label="Classes", placeholder="person, dog, cat...")
135
+ with gr.Accordion("Advanced Settings", open=False):
136
+ ye_conf = gr.Slider(0, 1, value=0.2, label="Confidence Threshold")
137
+ ye_retina = gr.Checkbox(value=True, label="Retina Masks", info="Higher quality masks, slower inference")
138
+ ye_btn = gr.Button("Run Inference", variant="primary")
139
+ with gr.Column():
140
+ ye_output = gr.Image(type="pil", label="Result")
141
+
142
+ gr.Examples(
143
+ examples=[
144
+ [str(ASSETS / "bus.jpg"), "YOLOE-26L", "person, bus, car", 0.2, True],
145
+ [str(ASSETS / "zidane.jpg"), "YOLOE-26L", "person, football, grass", 0.2, True],
146
+ ],
147
+ inputs=[ye_image, ye_model, ye_classes, ye_conf, ye_retina],
148
+ outputs=ye_output,
149
+ fn=predict_yoloe26,
150
+ cache_examples=True,
151
+ )
152
+ ye_btn.click(predict_yoloe26, [ye_image, ye_model, ye_classes, ye_conf, ye_retina], ye_output)
153
+
154
+ if __name__ == "__main__":
155
+ demo.launch(theme=theme, allowed_paths=[str(ASSETS), str(ASSETS.parent)])