Spaces:
Runtime error
Runtime error
KAHRAMAN42
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
from ultralytics import YOLO
|
4 |
+
|
5 |
+
def object_detection():
|
6 |
+
|
7 |
+
model=YOLO("/home/kahraman/Masaüstü/HuggingFace_Models_and_Spaces/yolov8_model_on_custom_data/best.pt")
|
8 |
+
|
9 |
+
source="/home/kahraman/Masaüstü/HuggingFace_Models_and_Spaces/yolov8_model_on_custom_data/cow-video-cows-mooing-and-grazing-in-a-field.mp4"
|
10 |
+
|
11 |
+
cap = cv2.VideoCapture(source)
|
12 |
+
|
13 |
+
while True:
|
14 |
+
ret, frame = cap.read()
|
15 |
+
|
16 |
+
if not ret:
|
17 |
+
break
|
18 |
+
|
19 |
+
results = model(frame)
|
20 |
+
for result in results:
|
21 |
+
box=result.boxes
|
22 |
+
|
23 |
+
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
24 |
+
print(x1, y1, x2, y2)
|
25 |
+
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
26 |
+
|
27 |
+
cv2.imshow("img", frame)
|
28 |
+
|
29 |
+
if cv2.waitKey(1) & 0xFF == ord("q"):
|
30 |
+
break
|
31 |
+
|
32 |
+
cap.release()
|
33 |
+
cv2.destroyAllWindows()
|
34 |
+
|
35 |
+
|
36 |
+
iface = gr.Interface(
|
37 |
+
fn=object_detection,
|
38 |
+
inputs="text",
|
39 |
+
outputs="text",
|
40 |
+
layout="vertical",
|
41 |
+
title="Sığır Object Detection",
|
42 |
+
description="Bir sığır videosu bırakın ve videoda ki sığırların yakalayın."
|
43 |
+
)
|
44 |
+
|
45 |
+
iface.launch(share=True)
|