Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,15 +4,26 @@ import numpy as np
|
|
| 4 |
import os
|
| 5 |
import gradio as gr
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def fonk(video_path):
|
| 8 |
|
| 9 |
-
model=YOLO(
|
| 10 |
cap=cv2.VideoCapture(video_path)
|
| 11 |
|
| 12 |
frame_width = int(cap.get(3))
|
| 13 |
frame_height = int(cap.get(4))
|
| 14 |
size = (frame_width, frame_height)
|
| 15 |
-
|
|
|
|
| 16 |
cv2.VideoWriter_fourcc(*"DIVX"),
|
| 17 |
10, size)
|
| 18 |
|
|
@@ -25,22 +36,22 @@ def fonk(video_path):
|
|
| 25 |
|
| 26 |
results= model(frame)
|
| 27 |
for result in results:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
|
| 36 |
writer.release()
|
| 37 |
cap.release()
|
| 38 |
-
return
|
| 39 |
|
| 40 |
demo = gr.Interface(fonk,
|
| 41 |
inputs= gr.Video(),
|
| 42 |
outputs=gr.Video(),
|
| 43 |
-
examples=[
|
| 44 |
title= "cows",
|
| 45 |
cache_examples=True)
|
| 46 |
demo.launch()
|
|
|
|
| 4 |
import os
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
|
| 8 |
+
__file__= "HUGGINGFACE _MODELS_AND_SPACES"
|
| 9 |
+
current_dırectory= os.path.dirname(os.path.abspath(__file__))
|
| 10 |
+
folder= os.path.join(current_dırectory,"Cattle_Detection_with_YOLOV8")
|
| 11 |
+
pt= os.path.join(folder, "best.pt")
|
| 12 |
+
py= os.path.join(folder, "Detection_Video.py")
|
| 13 |
+
rqrmt= os.path.join(folder, "requirements.txt")
|
| 14 |
+
example_video= os.path.join(folder, "cows-and-cows-and-cows.mp4")
|
| 15 |
+
output_video= os.path.join(folder, "output_video.mp4")
|
| 16 |
+
|
| 17 |
def fonk(video_path):
|
| 18 |
|
| 19 |
+
model=YOLO(pt)
|
| 20 |
cap=cv2.VideoCapture(video_path)
|
| 21 |
|
| 22 |
frame_width = int(cap.get(3))
|
| 23 |
frame_height = int(cap.get(4))
|
| 24 |
size = (frame_width, frame_height)
|
| 25 |
+
output_video= "output_video.mp4"
|
| 26 |
+
writer = cv2.VideoWriter(output_video,
|
| 27 |
cv2.VideoWriter_fourcc(*"DIVX"),
|
| 28 |
10, size)
|
| 29 |
|
|
|
|
| 36 |
|
| 37 |
results= model(frame)
|
| 38 |
for result in results:
|
| 39 |
+
if result.boxes is not None and len(result.boxes):
|
| 40 |
+
box = result.boxes
|
| 41 |
+
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
| 42 |
+
print(x1, y1, x2, y2)
|
| 43 |
+
frame = cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 44 |
+
writer.write(frame)
|
| 45 |
|
| 46 |
|
| 47 |
writer.release()
|
| 48 |
cap.release()
|
| 49 |
+
return output_video
|
| 50 |
|
| 51 |
demo = gr.Interface(fonk,
|
| 52 |
inputs= gr.Video(),
|
| 53 |
outputs=gr.Video(),
|
| 54 |
+
examples=[example_video],
|
| 55 |
title= "cows",
|
| 56 |
cache_examples=True)
|
| 57 |
demo.launch()
|