Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
import PIL.Image as Image
|
3 |
from ultralytics import YOLO, RTDETR
|
4 |
import spaces
|
5 |
import os
|
@@ -16,7 +16,20 @@ def get_model_path(model_name):
|
|
16 |
@spaces.GPU
|
17 |
def yolo_inference(images, model_id, conf_threshold, iou_threshold, max_detection):
|
18 |
if images is None:
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
model_path = get_model_path(model_id) # Download model
|
21 |
model_type = RTDETR if 'rtdetr' in model_id.lower() else YOLO
|
22 |
model = model_type(model_path)
|
|
|
1 |
import gradio as gr
|
2 |
+
import PIL.Image as Image, ImageDraw, ImageFont
|
3 |
from ultralytics import YOLO, RTDETR
|
4 |
import spaces
|
5 |
import os
|
|
|
16 |
@spaces.GPU
|
17 |
def yolo_inference(images, model_id, conf_threshold, iou_threshold, max_detection):
|
18 |
if images is None:
|
19 |
+
# Create a blank image
|
20 |
+
width, height = 640, 480
|
21 |
+
blank_image = Image.new("RGB", (width, height), color="white")
|
22 |
+
draw = ImageDraw.Draw(blank_image)
|
23 |
+
message = "No image provided."
|
24 |
+
font = ImageFont.load_default(size=40)
|
25 |
+
bbox = draw.textbbox((0, 0), message, font=font)
|
26 |
+
text_width = bbox[2] - bbox[0]
|
27 |
+
text_height = bbox[3] - bbox[1]
|
28 |
+
text_x = (width - text_width) / 2
|
29 |
+
text_y = (height - text_height) / 2
|
30 |
+
draw.text((text_x, text_y), message, fill="black", font=font)
|
31 |
+
return blank_image
|
32 |
+
|
33 |
model_path = get_model_path(model_id) # Download model
|
34 |
model_type = RTDETR if 'rtdetr' in model_id.lower() else YOLO
|
35 |
model = model_type(model_path)
|