Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
iface = gr.Interface(fn=greet, inputs="image", outputs="text")
|
| 8 |
iface.launch()
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
import gradio as gr
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
|
| 5 |
+
def process_frame(model, frame):
|
| 6 |
+
results = model(frame)
|
| 7 |
+
for result in results:
|
| 8 |
+
for box in result.boxes.data.tolist():
|
| 9 |
+
x1, y1, x2, y2, confidence, class_id = box
|
| 10 |
+
label = f"{model.names[int(class_id)]} {confidence:.2f}"
|
| 11 |
+
cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 3)
|
| 12 |
+
cv2.putText(frame, label, (int(x1), int(y1) - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
|
| 13 |
+
return frame
|
| 14 |
+
|
| 15 |
+
def detect_objects(image):
|
| 16 |
+
model = YOLO("s.pt") # Путь к вашей модели
|
| 17 |
+
processed_image = process_frame(model, image)
|
| 18 |
+
return processed_image
|
| 19 |
+
|
| 20 |
+
# Интерфейс Gradio
|
| 21 |
+
iface = gr.Interface(fn=detect_objects,
|
| 22 |
+
inputs=gr.Image(type="numpy"),
|
| 23 |
+
outputs=gr.Image(type="numpy"),
|
| 24 |
+
live=True)
|
| 25 |
|
|
|
|
| 26 |
iface.launch()
|