nomypython commited on
Commit
fc7f6fa
·
verified ·
1 Parent(s): a70a3b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -20
app.py CHANGED
@@ -1,20 +1,30 @@
1
- import gradio as gr
2
- from ultralytics import YOLO
3
- import os
4
-
5
- # Download the model from Google Drive if it's not present
6
- model_path = "best.pt"
7
-
8
- # Load the YOLOv8 model
9
- model = YOLO(model_path)
10
-
11
- # Define the object detection function
12
- def detect_objects(image):
13
- results = model(image)
14
- return results[0].plot()
15
-
16
- # Create a Gradio interface
17
- app = gr.Interface(fn=detect_objects, inputs="image", outputs="image")
18
-
19
- # Launch Gradio app
20
- app.launch()
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ import os
4
+ import sys
5
+ import io
6
+
7
+ # Load the YOLOv8 model
8
+ model = YOLO("best.pt")
9
+
10
+ # Define the object detection function
11
+ def detect_objects(image):
12
+ # Capture logs
13
+ old_stdout = sys.stdout
14
+ sys.stdout = io.StringIO()
15
+
16
+ # Run YOLO inference
17
+ results = model(image)
18
+
19
+ # Get inference logs
20
+ logs = sys.stdout.getvalue()
21
+ sys.stdout = old_stdout # Restore stdout
22
+
23
+ # Return both the image with detections and logs as text
24
+ return results[0].plot(), logs
25
+
26
+ # Create a Gradio interface with two outputs (image + logs)
27
+ app = gr.Interface(fn=detect_objects, inputs="image", outputs=["image", "text"])
28
+
29
+ # Launch Gradio app
30
+ app.launch()