tannu038 commited on
Commit
d225b91
·
verified ·
1 Parent(s): 86a1eaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -29
app.py CHANGED
@@ -1,29 +1,34 @@
1
- import gradio as gr
2
- from ultralytics import YOLO
3
- import os
4
- import glob
5
- # Load the trained YOLOv10 model
6
- model = YOLO('/content/runs/detect/train/weights/best.pt')
7
-
8
- # Inference function for Gradio
9
- def detect_objects(image):
10
- # Run prediction
11
- results = model.predict(source=image, save=True, conf=0.5)
12
-
13
- # Get the path of the saved image
14
- predicted_image_dir = 'runs/detect/predict'
15
- predicted_image_path = glob.glob(f"{predicted_image_dir}/*")
16
-
17
- return predicted_image_path[0]
18
-
19
- # Create the Gradio interface
20
- app = gr.Interface(
21
- fn=detect_objects,
22
- inputs=gr.Image(type="filepath", label="Upload Image"),
23
- outputs=gr.Image(type="filepath", label="Detected Image"),
24
- title="YOLOv10 Object Detection App",
25
- description="Upload an image to detect blood cells (RBC, WBC, Platelets) using the fine-tuned YOLOv10 model."
26
- )
27
-
28
- # Launch the app
29
- app.launch(share=True)
 
 
 
 
 
 
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()