Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,24 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
import torch
|
| 6 |
|
| 7 |
-
# Load your
|
| 8 |
-
model = YOLO("best.pt")
|
| 9 |
-
model.to('cpu') # force CPU
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
annotated = results[0].plot()
|
| 17 |
-
return Image.fromarray(annotated)
|
| 18 |
-
except Exception as e:
|
| 19 |
-
# Show error text on image
|
| 20 |
-
im = image.copy()
|
| 21 |
-
draw = ImageDraw.Draw(im)
|
| 22 |
-
draw.text((10, 10), f"Error: {e}", fill="red")
|
| 23 |
-
return im
|
| 24 |
|
| 25 |
# Gradio interface
|
| 26 |
iface = gr.Interface(
|
| 27 |
-
fn=
|
| 28 |
-
inputs=
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
outputs=gr.Image(type="pil", label="Detection Result"),
|
| 33 |
-
title="Automated Ear Disease Detection",
|
| 34 |
-
description="Detect ear conditions using YOLOv12 (CPU only)"
|
| 35 |
)
|
| 36 |
|
|
|
|
| 37 |
iface.launch()
|
|
|
|
|
|
|
| 1 |
from ultralytics import YOLO
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from PIL import Image
|
|
|
|
| 4 |
|
| 5 |
+
# Load your trained YOLOv12 model from the repo
|
| 6 |
+
model = YOLO("best.pt") # just the file name if it's in the same folder as app.py
|
|
|
|
| 7 |
|
| 8 |
+
# Define prediction function
|
| 9 |
+
def predict(image):
|
| 10 |
+
results = model.predict(image) # Run inference
|
| 11 |
+
annotated_img = results[0].plot() # Draw boxes on image
|
| 12 |
+
return annotated_img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Gradio interface
|
| 15 |
iface = gr.Interface(
|
| 16 |
+
fn=predict,
|
| 17 |
+
inputs=gr.Image(type="pil"),
|
| 18 |
+
outputs=gr.Image(type="pil"),
|
| 19 |
+
title="Ear Condition Detection",
|
| 20 |
+
description="Upload an otoscopic image and get predictions from the trained YOLOv12 model."
|
|
|
|
|
|
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
+
# Launch the app
|
| 24 |
iface.launch()
|