Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,30 +4,32 @@ from PIL import Image
|
|
| 4 |
import numpy as np
|
| 5 |
import sys, os
|
| 6 |
|
| 7 |
-
# ---- Add
|
| 8 |
fork_ultra_path = os.path.join(os.path.dirname(__file__), "yolov12-main", "yolov12-main")
|
| 9 |
sys.path.insert(0, fork_ultra_path)
|
| 10 |
|
| 11 |
-
# ----
|
| 12 |
from ultralytics import YOLO
|
| 13 |
|
| 14 |
-
# ---- Load
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
# ----
|
| 18 |
def detect_objects(image):
|
| 19 |
img = np.array(image)
|
| 20 |
results = model(img)
|
| 21 |
annotated = results[0].plot()
|
| 22 |
return Image.fromarray(annotated)
|
| 23 |
|
| 24 |
-
# ---- Gradio
|
| 25 |
-
|
| 26 |
fn=detect_objects,
|
| 27 |
-
inputs=gr.Image(type="pil"),
|
| 28 |
-
outputs=gr.Image(type="pil"),
|
| 29 |
-
title="Ear Condition Detection
|
| 30 |
-
description="
|
| 31 |
)
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import sys, os
|
| 6 |
|
| 7 |
+
# ---- Add YOLOv12 code to Python path ----
|
| 8 |
fork_ultra_path = os.path.join(os.path.dirname(__file__), "yolov12-main", "yolov12-main")
|
| 9 |
sys.path.insert(0, fork_ultra_path)
|
| 10 |
|
| 11 |
+
# ---- Import YOLO ----
|
| 12 |
from ultralytics import YOLO
|
| 13 |
|
| 14 |
+
# ---- Load trained model ----
|
| 15 |
+
model_path = os.path.join(os.path.dirname(__file__), "best.pt")
|
| 16 |
+
model = YOLO(model_path)
|
| 17 |
|
| 18 |
+
# ---- Detection function ----
|
| 19 |
def detect_objects(image):
|
| 20 |
img = np.array(image)
|
| 21 |
results = model(img)
|
| 22 |
annotated = results[0].plot()
|
| 23 |
return Image.fromarray(annotated)
|
| 24 |
|
| 25 |
+
# ---- Gradio Interface ----
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
fn=detect_objects,
|
| 28 |
+
inputs=gr.Image(type="pil", label="Upload an Ear Image"),
|
| 29 |
+
outputs=gr.Image(type="pil", label="Detection Result"),
|
| 30 |
+
title="Ear Condition Detection",
|
| 31 |
+
description="Upload an ear image to detect possible conditions using the trained YOLOv12 model."
|
| 32 |
)
|
| 33 |
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|