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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -1,29 +1,21 @@
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
 
1
  import gradio as gr
2
  from ultralytics import YOLO
3
  import os
 
 
4
 
5
+ # Load the YOLO model
6
+ model_path = "best.pt"
7
+ model = YOLO(model_path)
8
 
9
  # Define the object detection function
10
  def detect_objects(image):
 
 
 
 
 
11
  results = model(image)
12
 
13
+ # Extract logs from YOLO results
14
+ logs = results[0].verbose()
 
15
 
16
+ return results[0].plot(), logs # Return image + logs
 
17
 
18
+ # Create a Gradio interface
19
  app = gr.Interface(fn=detect_objects, inputs="image", outputs=["image", "text"])
20
 
21
  # Launch Gradio app