Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,34 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from ultralytics import YOLO
|
| 3 |
-
import os
|
| 4 |
-
import glob
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
import os
|
| 4 |
+
import glob
|
| 5 |
+
import shutil
|
| 6 |
+
|
| 7 |
+
# Load the fine-tuned YOLOv10 model
|
| 8 |
+
model = YOLO('best.pt')
|
| 9 |
+
|
| 10 |
+
# Inference function for Gradio
|
| 11 |
+
def detect_objects(image):
|
| 12 |
+
# Create a predict directory if it doesn't exist
|
| 13 |
+
output_dir = "predict"
|
| 14 |
+
if not os.path.exists(output_dir):
|
| 15 |
+
os.makedirs(output_dir)
|
| 16 |
+
|
| 17 |
+
# Run prediction and save results in the output directory
|
| 18 |
+
results = model.predict(source=image, save=True, project=output_dir, name='results', conf=0.5)
|
| 19 |
+
|
| 20 |
+
# Get the latest saved image
|
| 21 |
+
predicted_image_path = glob.glob(f"{output_dir}/results/*")[-1]
|
| 22 |
+
return predicted_image_path
|
| 23 |
+
|
| 24 |
+
# Create the Gradio interface
|
| 25 |
+
app = gr.Interface(
|
| 26 |
+
fn=detect_objects,
|
| 27 |
+
inputs=gr.Image(type="filepath", label="📤 Upload Image"),
|
| 28 |
+
outputs=gr.Image(type="filepath", label="✅ Detected Image"),
|
| 29 |
+
title="🔬 YOLOv10 Blood Cell Detection App",
|
| 30 |
+
description="Upload an image to detect blood cells (RBC, WBC, Platelets) using the fine-tuned YOLOv10 model."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Launch the app
|
| 34 |
+
app.launch()
|