Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import sys
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
|
@@ -6,6 +16,7 @@ import cv2
|
|
| 6 |
import requests
|
| 7 |
from ultralytics import YOLO
|
| 8 |
|
|
|
|
| 9 |
sys.argv = [arg for arg in sys.argv if arg != "--import"]
|
| 10 |
|
| 11 |
model = YOLO("yolo11n-pose.pt")
|
|
@@ -65,8 +76,7 @@ def process_input(uploaded_file, youtube_link, image_url, sensitivity):
|
|
| 65 |
return None, None, None, "Invalid video properties detected."
|
| 66 |
|
| 67 |
output_path = os.path.join(tempfile.gettempdir(), f"out_{os.urandom(8).hex()}.mp4")
|
| 68 |
-
|
| 69 |
-
fourcc = cv2.VideoWriter_fourcc(*'avc1') # Changed from 'mp4v' to 'avc1'
|
| 70 |
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
| 71 |
|
| 72 |
if not out.isOpened():
|
|
@@ -94,7 +104,7 @@ def process_input(uploaded_file, youtube_link, image_url, sensitivity):
|
|
| 94 |
if processed_frames == 0:
|
| 95 |
return None, None, None, "No frames processed from video."
|
| 96 |
|
| 97 |
-
if not os.path.exists(output_path) or os.path.getsize(output_path) < 1024:
|
| 98 |
return None, None, None, f"Output video created but too small ({os.path.getsize(output_path)} bytes) - processing failed."
|
| 99 |
|
| 100 |
return output_path, None, output_path, f"Video processed successfully! ({processed_frames}/{frame_count} frames)"
|
|
@@ -119,7 +129,6 @@ def process_input(uploaded_file, youtube_link, image_url, sensitivity):
|
|
| 119 |
except:
|
| 120 |
pass
|
| 121 |
|
| 122 |
-
# Gradio interface (unchanged)
|
| 123 |
with gr.Blocks(css="""
|
| 124 |
.result_img > img {
|
| 125 |
width: 100%;
|
|
|
|
| 1 |
+
# This script is designed for Hugging Face Spaces
|
| 2 |
+
# Dependencies are specified in requirements.txt in the Space's repository root
|
| 3 |
+
# Expected dependencies:
|
| 4 |
+
# gradio>=4.0.0
|
| 5 |
+
# opencv-python>=4.8.0
|
| 6 |
+
# requests>=2.28.0
|
| 7 |
+
# ultralytics>=8.2.0
|
| 8 |
+
# pytubefix>=6.0.0
|
| 9 |
+
# numpy>=1.23.0
|
| 10 |
+
|
| 11 |
import sys
|
| 12 |
import gradio as gr
|
| 13 |
import os
|
|
|
|
| 16 |
import requests
|
| 17 |
from ultralytics import YOLO
|
| 18 |
|
| 19 |
+
# Remove extra CLI arguments that Spaces might pass
|
| 20 |
sys.argv = [arg for arg in sys.argv if arg != "--import"]
|
| 21 |
|
| 22 |
model = YOLO("yolo11n-pose.pt")
|
|
|
|
| 76 |
return None, None, None, "Invalid video properties detected."
|
| 77 |
|
| 78 |
output_path = os.path.join(tempfile.gettempdir(), f"out_{os.urandom(8).hex()}.mp4")
|
| 79 |
+
fourcc = cv2.VideoWriter_fourcc(*'avc1')
|
|
|
|
| 80 |
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
| 81 |
|
| 82 |
if not out.isOpened():
|
|
|
|
| 104 |
if processed_frames == 0:
|
| 105 |
return None, None, None, "No frames processed from video."
|
| 106 |
|
| 107 |
+
if not os.path.exists(output_path) or os.path.getsize(output_path) < 1024:
|
| 108 |
return None, None, None, f"Output video created but too small ({os.path.getsize(output_path)} bytes) - processing failed."
|
| 109 |
|
| 110 |
return output_path, None, output_path, f"Video processed successfully! ({processed_frames}/{frame_count} frames)"
|
|
|
|
| 129 |
except:
|
| 130 |
pass
|
| 131 |
|
|
|
|
| 132 |
with gr.Blocks(css="""
|
| 133 |
.result_img > img {
|
| 134 |
width: 100%;
|