Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -195,8 +195,8 @@ def create_overlay_thumbnail(rgb_frame, depth_frame):
|
|
| 195 |
|
| 196 |
def create_rounded_corner_mask(width, height):
|
| 197 |
"""Erstellt Anti-Aliased Maske mit abgerundeter oberer linker Ecke"""
|
| 198 |
-
# Radius für die Rundung (
|
| 199 |
-
radius = min(width, height)
|
| 200 |
radius = max(radius, 5) # Minimum 5 Pixel
|
| 201 |
|
| 202 |
# Erstelle Maske (weiß = sichtbar, schwarz = transparent)
|
|
@@ -364,16 +364,68 @@ def validate_url(url):
|
|
| 364 |
except:
|
| 365 |
return False
|
| 366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
def detect_video_source(url):
|
| 368 |
-
"""Detect video source
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
if "image.civitai.com" in url:
|
| 370 |
return "civitai"
|
| 371 |
-
elif "v21-kling.klingai.com" in url or "kling.ai" in url:
|
| 372 |
-
return "kling"
|
| 373 |
elif "cdn.midjourney.com" in url or "midjourney" in url.lower():
|
| 374 |
return "midjourney"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
else:
|
| 376 |
-
return "
|
| 377 |
|
| 378 |
def optimize_civitai_url(url):
|
| 379 |
"""Convert gallery Civitai URLs to original quality to avoid dimension issues"""
|
|
@@ -438,7 +490,7 @@ def download_civitai_video(civitai_url):
|
|
| 438 |
raise RuntimeError(f"Failed to download Civitai video: {e}")
|
| 439 |
|
| 440 |
def download_video_from_url(original_url):
|
| 441 |
-
"""Universal video downloader
|
| 442 |
try:
|
| 443 |
if not validate_url(original_url):
|
| 444 |
raise ValueError("Invalid URL format")
|
|
@@ -447,10 +499,23 @@ def download_video_from_url(original_url):
|
|
| 447 |
source = detect_video_source(original_url)
|
| 448 |
print(f"DEBUG: Detected video source: {source}")
|
| 449 |
|
| 450 |
-
if source == "
|
|
|
|
|
|
|
| 451 |
return download_civitai_video(original_url)
|
| 452 |
elif source == "midjourney":
|
| 453 |
return download_midjourney_video(original_url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
else:
|
| 455 |
return download_generic_video(original_url)
|
| 456 |
|
|
@@ -775,6 +840,22 @@ def on_video_url_change(url, use_blip):
|
|
| 775 |
|
| 776 |
elif source == "midjourney":
|
| 777 |
original_filename = "midjourney_video"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 778 |
else:
|
| 779 |
original_filename = "downloaded_video"
|
| 780 |
|
|
@@ -853,7 +934,7 @@ with gr.Blocks(analytics_enabled=False, title="Video Depth Anything") as demo:
|
|
| 853 |
# 🎥 Video Depth Anything + RGBD Output
|
| 854 |
|
| 855 |
Generate depth maps from videos and watch RGBD videos on holographic displays like Looking Glass Go.
|
| 856 |
-
Upload a video or paste a video URL
|
| 857 |
|
| 858 |
[🔗 Project Page](https://videodepthanything.github.io/) | [📖 Paper](https://arxiv.org/abs/2401.01884)
|
| 859 |
""")
|
|
@@ -888,8 +969,8 @@ with gr.Blocks(analytics_enabled=False, title="Video Depth Anything") as demo:
|
|
| 888 |
# Single row with all input controls and thumbnail preview
|
| 889 |
with gr.Row():
|
| 890 |
video_url = gr.Textbox(
|
| 891 |
-
label="Video URL (
|
| 892 |
-
placeholder="Paste MidJourney, Civitai, or
|
| 893 |
scale=3
|
| 894 |
)
|
| 895 |
use_blip = gr.Checkbox(
|
|
|
|
| 195 |
|
| 196 |
def create_rounded_corner_mask(width, height):
|
| 197 |
"""Erstellt Anti-Aliased Maske mit abgerundeter oberer linker Ecke"""
|
| 198 |
+
# Radius für die Rundung (40% der kleineren Dimension)
|
| 199 |
+
radius = int(min(width, height) * 0.40)
|
| 200 |
radius = max(radius, 5) # Minimum 5 Pixel
|
| 201 |
|
| 202 |
# Erstelle Maske (weiß = sichtbar, schwarz = transparent)
|
|
|
|
| 364 |
except:
|
| 365 |
return False
|
| 366 |
|
| 367 |
+
def download_video_with_ytdlp(url):
|
| 368 |
+
"""Universal video download using yt-dlp for maximum compatibility"""
|
| 369 |
+
try:
|
| 370 |
+
import time
|
| 371 |
+
temp_path = f"temp_ytdlp_{int(time.time())}.%(ext)s"
|
| 372 |
+
|
| 373 |
+
# yt-dlp command with best quality settings
|
| 374 |
+
cmd = [
|
| 375 |
+
"yt-dlp",
|
| 376 |
+
"--format", "best[ext=mp4]/best", # Prefer MP4, fallback to best available
|
| 377 |
+
"--output", temp_path,
|
| 378 |
+
"--no-playlist", # Only download single video
|
| 379 |
+
"--no-part", # Don't create .part files
|
| 380 |
+
url
|
| 381 |
+
]
|
| 382 |
+
|
| 383 |
+
print(f"DEBUG: Downloading with yt-dlp: {url}")
|
| 384 |
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
| 385 |
+
|
| 386 |
+
if result.returncode != 0:
|
| 387 |
+
raise RuntimeError(f"yt-dlp failed: {result.stderr}")
|
| 388 |
+
|
| 389 |
+
# Find the actual downloaded file (yt-dlp replaces %(ext)s)
|
| 390 |
+
import glob
|
| 391 |
+
temp_base = temp_path.replace(".%(ext)s", "")
|
| 392 |
+
downloaded_files = glob.glob(f"{temp_base}.*")
|
| 393 |
+
|
| 394 |
+
if not downloaded_files:
|
| 395 |
+
raise RuntimeError("yt-dlp completed but no file found")
|
| 396 |
+
|
| 397 |
+
actual_path = downloaded_files[0]
|
| 398 |
+
print(f"DEBUG: yt-dlp downloaded: {actual_path}")
|
| 399 |
+
return actual_path
|
| 400 |
+
|
| 401 |
+
except Exception as e:
|
| 402 |
+
raise RuntimeError(f"Failed to download with yt-dlp: {e}")
|
| 403 |
+
|
| 404 |
def detect_video_source(url):
|
| 405 |
+
"""Detect video source and determine download method"""
|
| 406 |
+
# Direct video file URLs (priority check first)
|
| 407 |
+
if any(ext in url.lower() for ext in ['.mp4', '.webm', '.mov', '.avi', '.mkv']):
|
| 408 |
+
return "direct_video"
|
| 409 |
+
|
| 410 |
+
# Known platforms with direct download support
|
| 411 |
if "image.civitai.com" in url:
|
| 412 |
return "civitai"
|
|
|
|
|
|
|
| 413 |
elif "cdn.midjourney.com" in url or "midjourney" in url.lower():
|
| 414 |
return "midjourney"
|
| 415 |
+
elif "v21-kling.klingai.com" in url or "kling.ai" in url:
|
| 416 |
+
return "kling"
|
| 417 |
+
|
| 418 |
+
# Popular video platforms (use yt-dlp)
|
| 419 |
+
elif any(platform in url.lower() for platform in [
|
| 420 |
+
'youtube.com', 'youtu.be', 'vimeo.com', 'dailymotion.com',
|
| 421 |
+
'tiktok.com', 'instagram.com', 'twitter.com', 'x.com',
|
| 422 |
+
'facebook.com', 'reddit.com', 'twitch.tv'
|
| 423 |
+
]):
|
| 424 |
+
return "ytdlp_platform"
|
| 425 |
+
|
| 426 |
+
# Unknown URL - try yt-dlp first, fallback to direct
|
| 427 |
else:
|
| 428 |
+
return "ytdlp_fallback"
|
| 429 |
|
| 430 |
def optimize_civitai_url(url):
|
| 431 |
"""Convert gallery Civitai URLs to original quality to avoid dimension issues"""
|
|
|
|
| 490 |
raise RuntimeError(f"Failed to download Civitai video: {e}")
|
| 491 |
|
| 492 |
def download_video_from_url(original_url):
|
| 493 |
+
"""Universal video downloader with yt-dlp integration"""
|
| 494 |
try:
|
| 495 |
if not validate_url(original_url):
|
| 496 |
raise ValueError("Invalid URL format")
|
|
|
|
| 499 |
source = detect_video_source(original_url)
|
| 500 |
print(f"DEBUG: Detected video source: {source}")
|
| 501 |
|
| 502 |
+
if source == "direct_video":
|
| 503 |
+
return download_generic_video(original_url)
|
| 504 |
+
elif source == "civitai":
|
| 505 |
return download_civitai_video(original_url)
|
| 506 |
elif source == "midjourney":
|
| 507 |
return download_midjourney_video(original_url)
|
| 508 |
+
elif source == "kling":
|
| 509 |
+
return download_generic_video(original_url) # Kling usually works with direct download
|
| 510 |
+
elif source == "ytdlp_platform":
|
| 511 |
+
return download_video_with_ytdlp(original_url)
|
| 512 |
+
elif source == "ytdlp_fallback":
|
| 513 |
+
# Try yt-dlp first, fallback to direct download
|
| 514 |
+
try:
|
| 515 |
+
return download_video_with_ytdlp(original_url)
|
| 516 |
+
except Exception as ytdlp_error:
|
| 517 |
+
print(f"DEBUG: yt-dlp failed, trying direct download: {ytdlp_error}")
|
| 518 |
+
return download_generic_video(original_url)
|
| 519 |
else:
|
| 520 |
return download_generic_video(original_url)
|
| 521 |
|
|
|
|
| 840 |
|
| 841 |
elif source == "midjourney":
|
| 842 |
original_filename = "midjourney_video"
|
| 843 |
+
elif source == "kling":
|
| 844 |
+
original_filename = "kling_video"
|
| 845 |
+
elif source == "direct_video":
|
| 846 |
+
# Extract filename from direct video URL
|
| 847 |
+
parsed_url = urlparse(url)
|
| 848 |
+
url_filename = os.path.splitext(os.path.basename(parsed_url.path))[0]
|
| 849 |
+
cleaned = "".join(c for c in url_filename if c.isalnum() or c in "_-")[:20]
|
| 850 |
+
original_filename = cleaned if cleaned else "direct_video"
|
| 851 |
+
elif source in ["ytdlp_platform", "ytdlp_fallback"]:
|
| 852 |
+
# Extract domain name for yt-dlp downloads
|
| 853 |
+
parsed_url = urlparse(url)
|
| 854 |
+
domain = parsed_url.netloc.lower()
|
| 855 |
+
# Remove www. and common prefixes
|
| 856 |
+
domain = domain.replace('www.', '').replace('m.', '')
|
| 857 |
+
domain_name = domain.split('.')[0] # Get main domain part
|
| 858 |
+
original_filename = f"{domain_name}_video"
|
| 859 |
else:
|
| 860 |
original_filename = "downloaded_video"
|
| 861 |
|
|
|
|
| 934 |
# 🎥 Video Depth Anything + RGBD Output
|
| 935 |
|
| 936 |
Generate depth maps from videos and watch RGBD videos on holographic displays like Looking Glass Go.
|
| 937 |
+
Upload a video or paste a video URL from **YouTube, TikTok, Instagram, MidJourney, Civitai**, or any platform.
|
| 938 |
|
| 939 |
[🔗 Project Page](https://videodepthanything.github.io/) | [📖 Paper](https://arxiv.org/abs/2401.01884)
|
| 940 |
""")
|
|
|
|
| 969 |
# Single row with all input controls and thumbnail preview
|
| 970 |
with gr.Row():
|
| 971 |
video_url = gr.Textbox(
|
| 972 |
+
label="Video URL (YouTube, TikTok, Instagram, Civitai, MidJourney, etc.)",
|
| 973 |
+
placeholder="Paste video URL from YouTube, TikTok, Instagram, MidJourney, Civitai, or any platform...",
|
| 974 |
scale=3
|
| 975 |
)
|
| 976 |
use_blip = gr.Checkbox(
|