Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,9 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import supervision as sv
|
| 4 |
-
from PIL import ImageDraw
|
| 5 |
-
import PIL.Image as Image
|
| 6 |
import PIL.Image as Image
|
| 7 |
from ultralytics import YOLO
|
| 8 |
from huggingface_hub import hf_hub_download, HfApi
|
| 9 |
-
|
| 10 |
global repo_id
|
| 11 |
|
| 12 |
def download_models(model_id):
|
|
@@ -19,9 +16,6 @@ def get_model_filenames(repo_id, file_extension = ".pt"):
|
|
| 19 |
model_filenames = [file for file in files if file.endswith(file_extension)]
|
| 20 |
return model_filenames
|
| 21 |
|
| 22 |
-
def random_color():
|
| 23 |
-
return tuple(random.randint(0, 255) for _ in range(3))
|
| 24 |
-
|
| 25 |
repo_id = "atalaydenknalbant/asl-yolo-models"
|
| 26 |
model_filenames = get_model_filenames(repo_id)
|
| 27 |
print("Model filenames:", model_filenames)
|
|
@@ -39,22 +33,13 @@ def yolo_inference(image, model_id, conf_threshold, iou_threshold, max_detection
|
|
| 39 |
model_path = download_models(model_id)
|
| 40 |
model = YOLO(model_path)
|
| 41 |
results = model(source=image, imgsz=640, iou=iou_threshold, conf=conf_threshold, verbose=False, max_det=max_detection)[0]
|
| 42 |
-
|
| 43 |
detections = sv.Detections.from_ultralytics(results)
|
| 44 |
|
| 45 |
labels = [
|
| 46 |
f"{category_dict[class_id]} {confidence:.2f}"
|
| 47 |
for class_id, confidence in zip(detections.class_id, detections.confidence)
|
| 48 |
]
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
annotated_image = image.copy()
|
| 52 |
-
draw = ImageDraw.Draw(annotated_image)
|
| 53 |
-
|
| 54 |
-
for label, (x1, y1, x2, y2) in zip(labels, detections.xyxy):
|
| 55 |
-
color = random_color()
|
| 56 |
-
draw.rectangle([x1, y1, x2, y2], outline=color, width=3)
|
| 57 |
-
draw.text((x1, y1), label, fill=color)
|
| 58 |
|
| 59 |
return annotated_image
|
| 60 |
|
|
|
|
|
|
|
| 1 |
import spaces
|
| 2 |
import supervision as sv
|
|
|
|
|
|
|
| 3 |
import PIL.Image as Image
|
| 4 |
from ultralytics import YOLO
|
| 5 |
from huggingface_hub import hf_hub_download, HfApi
|
| 6 |
+
|
| 7 |
global repo_id
|
| 8 |
|
| 9 |
def download_models(model_id):
|
|
|
|
| 16 |
model_filenames = [file for file in files if file.endswith(file_extension)]
|
| 17 |
return model_filenames
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
repo_id = "atalaydenknalbant/asl-yolo-models"
|
| 20 |
model_filenames = get_model_filenames(repo_id)
|
| 21 |
print("Model filenames:", model_filenames)
|
|
|
|
| 33 |
model_path = download_models(model_id)
|
| 34 |
model = YOLO(model_path)
|
| 35 |
results = model(source=image, imgsz=640, iou=iou_threshold, conf=conf_threshold, verbose=False, max_det=max_detection)[0]
|
|
|
|
| 36 |
detections = sv.Detections.from_ultralytics(results)
|
| 37 |
|
| 38 |
labels = [
|
| 39 |
f"{category_dict[class_id]} {confidence:.2f}"
|
| 40 |
for class_id, confidence in zip(detections.class_id, detections.confidence)
|
| 41 |
]
|
| 42 |
+
annotated_image = box_annotator.annotate(image, detections=detections, labels=labels)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
return annotated_image
|
| 45 |
|