Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 8 |
-
|
|
|
|
| 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 |
-
#
|
| 20 |
-
logs =
|
| 21 |
-
sys.stdout = old_stdout # Restore stdout
|
| 22 |
|
| 23 |
-
# Return
|
| 24 |
-
return results[0].plot(), logs
|
| 25 |
|
| 26 |
-
# Create a Gradio interface
|
| 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
|