Spaces:
Sleeping
Sleeping
Devank Upadhyaya commited on
Commit ·
df7a9df
1
Parent(s): 41410d8
Reduce yt-dlp timeout and increase Gunicorn timeout
Browse files- Dockerfile +1 -1
- tools.py +6 -5
Dockerfile
CHANGED
|
@@ -35,4 +35,4 @@ ENV PORT=7860
|
|
| 35 |
EXPOSE 7860
|
| 36 |
|
| 37 |
# Run the Flask app using Gunicorn
|
| 38 |
-
CMD ["gunicorn", "app:app", "-b", "0.0.0.0:7860", "--timeout", "
|
|
|
|
| 35 |
EXPOSE 7860
|
| 36 |
|
| 37 |
# Run the Flask app using Gunicorn
|
| 38 |
+
CMD ["gunicorn", "app:app", "-b", "0.0.0.0:7860", "--timeout", "300"]
|
tools.py
CHANGED
|
@@ -141,14 +141,15 @@ def extract_angles_from_video(video_path: str, sample_fps: int = 2) -> dict:
|
|
| 141 |
# ─────────────────────────────────────────────────
|
| 142 |
def download_youtube_video(url: str, out_path: str) -> str:
|
| 143 |
logger.debug(f"Downloading YouTube video: {url}")
|
| 144 |
-
|
|
|
|
| 145 |
last_error = ""
|
| 146 |
|
| 147 |
for fmt in format_options:
|
| 148 |
-
cmd = ["yt-dlp", "-f", fmt, "--no-playlist", "--no-warnings", "-o", out_path, url]
|
| 149 |
logger.debug(f"Trying yt-dlp format: {fmt}")
|
| 150 |
try:
|
| 151 |
-
result = subprocess.run(cmd, capture_output=True, text=True, timeout=
|
| 152 |
if result.returncode == 0 and os.path.exists(out_path):
|
| 153 |
logger.debug(f"Download succeeded: {fmt}")
|
| 154 |
return out_path
|
|
@@ -159,8 +160,8 @@ def download_youtube_video(url: str, out_path: str) -> str:
|
|
| 159 |
|
| 160 |
fallback_template = out_path.replace(".mp4", ".%(ext)s")
|
| 161 |
try:
|
| 162 |
-
subprocess.run(["yt-dlp", "--no-playlist", "--no-warnings", "-o", fallback_template, url],
|
| 163 |
-
capture_output=True, text=True, timeout=
|
| 164 |
except subprocess.TimeoutExpired as e:
|
| 165 |
logger.error(f"Fallback timeout: {e}")
|
| 166 |
|
|
|
|
| 141 |
# ─────────────────────────────────────────────────
|
| 142 |
def download_youtube_video(url: str, out_path: str) -> str:
|
| 143 |
logger.debug(f"Downloading YouTube video: {url}")
|
| 144 |
+
# Hugging Face IP might be throttled; use smaller formats and strict timeouts
|
| 145 |
+
format_options = ["worst", "best[height<=480]", "best[ext=mp4]"]
|
| 146 |
last_error = ""
|
| 147 |
|
| 148 |
for fmt in format_options:
|
| 149 |
+
cmd = ["yt-dlp", "-f", fmt, "--socket-timeout", "15", "--no-playlist", "--no-warnings", "-o", out_path, url]
|
| 150 |
logger.debug(f"Trying yt-dlp format: {fmt}")
|
| 151 |
try:
|
| 152 |
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=25)
|
| 153 |
if result.returncode == 0 and os.path.exists(out_path):
|
| 154 |
logger.debug(f"Download succeeded: {fmt}")
|
| 155 |
return out_path
|
|
|
|
| 160 |
|
| 161 |
fallback_template = out_path.replace(".mp4", ".%(ext)s")
|
| 162 |
try:
|
| 163 |
+
subprocess.run(["yt-dlp", "--socket-timeout", "15", "--no-playlist", "--no-warnings", "-o", fallback_template, url],
|
| 164 |
+
capture_output=True, text=True, timeout=25)
|
| 165 |
except subprocess.TimeoutExpired as e:
|
| 166 |
logger.error(f"Fallback timeout: {e}")
|
| 167 |
|