Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,23 @@
|
|
| 1 |
from ultralytics import YOLO
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
|
|
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
model = YOLO("best.pt") #
|
| 7 |
|
| 8 |
-
# Define prediction function
|
| 9 |
def predict(image):
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
return annotated_img
|
| 13 |
|
| 14 |
-
# Gradio interface
|
| 15 |
iface = gr.Interface(
|
| 16 |
fn=predict,
|
| 17 |
inputs=gr.Image(type="pil"),
|
|
@@ -20,5 +26,4 @@ iface = gr.Interface(
|
|
| 20 |
description="Upload an otoscopic image and get predictions from the trained YOLOv12 model."
|
| 21 |
)
|
| 22 |
|
| 23 |
-
# Launch the app
|
| 24 |
iface.launch()
|
|
|
|
| 1 |
from ultralytics import YOLO
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
|
| 6 |
+
# Load YOLOv12 model
|
| 7 |
+
model = YOLO("best.pt") # model in repo
|
| 8 |
|
|
|
|
| 9 |
def predict(image):
|
| 10 |
+
# Ensure RGB and convert to NumPy array
|
| 11 |
+
image = image.convert("RGB")
|
| 12 |
+
img_array = np.array(image)
|
| 13 |
+
|
| 14 |
+
# Run inference
|
| 15 |
+
results = model.predict(img_array)
|
| 16 |
+
|
| 17 |
+
# Annotate and return
|
| 18 |
+
annotated_img = results[0].plot()
|
| 19 |
return annotated_img
|
| 20 |
|
|
|
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=predict,
|
| 23 |
inputs=gr.Image(type="pil"),
|
|
|
|
| 26 |
description="Upload an otoscopic image and get predictions from the trained YOLOv12 model."
|
| 27 |
)
|
| 28 |
|
|
|
|
| 29 |
iface.launch()
|