aastha-malik commited on
Commit
337462b
Β·
1 Parent(s): fa37ee5

Upload-only: remove YouTube (DNS blocked on HF free tier), show clear message

Browse files
Files changed (2) hide show
  1. app.py +8 -35
  2. requirements.txt +0 -1
app.py CHANGED
@@ -55,32 +55,13 @@ def to_h264(src: str, dst: str):
55
  )
56
 
57
 
58
- def download_youtube(url: str, out_path: str):
59
- import yt_dlp
60
- raw = out_path.replace(".mp4", "_raw.mp4")
61
- ydl_opts = {
62
- "outtmpl": raw,
63
- "format": "best[height<=480]/best",
64
- "http_headers": {
65
- "User-Agent": (
66
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
67
- "AppleWebKit/537.36 Chrome/120.0.0.0 Safari/537.36"
68
- )
69
- },
70
- }
71
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
72
- ydl.download([url])
73
- to_h264(raw, out_path)
74
- if os.path.exists(raw):
75
- os.remove(raw)
76
-
77
 
78
  # ── Core processing ──────────────────────────────────────────────────
79
- def process(face_image, video_file, youtube_url, trim_seconds, progress=gr.Progress(track_tqdm=True)):
80
  if face_image is None:
81
  return None, "Please upload a source face image."
82
- if video_file is None and not (youtube_url or "").strip():
83
- return None, "Please upload a video file or paste a YouTube URL."
84
 
85
  try:
86
  progress(0.0, desc="Detecting source face...")
@@ -102,16 +83,12 @@ def process(face_image, video_file, youtube_url, trim_seconds, progress=gr.Progr
102
  source_face.embedding /= np.linalg.norm(source_face.embedding)
103
 
104
  # Prepare video
 
105
  raw_video = f"{WORK_DIR}/temp/input.mp4"
106
  converted = f"{WORK_DIR}/temp/input_h264.mp4"
107
 
108
- if (youtube_url or "").strip():
109
- progress(0.05, desc="Downloading YouTube video...")
110
- download_youtube(youtube_url.strip(), converted)
111
- else:
112
- progress(0.05, desc="Preparing video...")
113
- shutil.copy(video_file, raw_video)
114
- to_h264(raw_video, converted)
115
 
116
  # Verify codec
117
  cap_check = cv2.VideoCapture(converted)
@@ -200,11 +177,7 @@ Swap any face into a video using **InsightFace + inswapper_128**.
200
  type="filepath",
201
  height=220,
202
  )
203
- youtube_input = gr.Textbox(
204
- label="YouTube URL (optional)",
205
- placeholder="https://www.youtube.com/watch?v=...",
206
- )
207
- gr.Markdown("**β€” or β€”**")
208
  video_input = gr.Video(label="Upload Video File")
209
  trim_input = gr.Slider(
210
  label="Trim to first N seconds (0 = full video)",
@@ -226,7 +199,7 @@ Swap any face into a video using **InsightFace + inswapper_128**.
226
 
227
  run_btn.click(
228
  fn=process,
229
- inputs=[face_input, video_input, youtube_input, trim_input],
230
  outputs=[video_out, status_box],
231
  )
232
 
 
55
  )
56
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  # ── Core processing ──────────────────────────────────────────────────
60
+ def process(face_image, video_file, trim_seconds, progress=gr.Progress(track_tqdm=True)):
61
  if face_image is None:
62
  return None, "Please upload a source face image."
63
+ if video_file is None:
64
+ return None, "Please upload a video file."
65
 
66
  try:
67
  progress(0.0, desc="Detecting source face...")
 
83
  source_face.embedding /= np.linalg.norm(source_face.embedding)
84
 
85
  # Prepare video
86
+ progress(0.05, desc="Preparing video...")
87
  raw_video = f"{WORK_DIR}/temp/input.mp4"
88
  converted = f"{WORK_DIR}/temp/input_h264.mp4"
89
 
90
+ shutil.copy(video_file, raw_video)
91
+ to_h264(raw_video, converted)
 
 
 
 
 
92
 
93
  # Verify codec
94
  cap_check = cv2.VideoCapture(converted)
 
177
  type="filepath",
178
  height=220,
179
  )
180
+ gr.Markdown("> ⚠️ **YouTube URLs don't work on HF free Spaces** (DNS blocked). Download your video locally first, then upload it below.")
 
 
 
 
181
  video_input = gr.Video(label="Upload Video File")
182
  trim_input = gr.Slider(
183
  label="Trim to first N seconds (0 = full video)",
 
199
 
200
  run_btn.click(
201
  fn=process,
202
+ inputs=[face_input, video_input, trim_input],
203
  outputs=[video_out, status_box],
204
  )
205
 
requirements.txt CHANGED
@@ -2,5 +2,4 @@ insightface==0.7.3
2
  onnxruntime
3
  opencv-python-headless
4
  huggingface_hub
5
- yt-dlp
6
  gradio
 
2
  onnxruntime
3
  opencv-python-headless
4
  huggingface_hub
 
5
  gradio