AIBRUH commited on
Commit
bb1b5ea
·
verified ·
1 Parent(s): 837c15e

fix: remove GFPGAN download, skip enhancer (not needed)

Browse files
Files changed (1) hide show
  1. app.py +44 -26
app.py CHANGED
@@ -1,35 +1,49 @@
1
  """
2
  AIBRUH/ditto — Amanda's talking head engine.
3
- SadTalker-backed portrait animation: image + audio → MP4.
4
- ZeroGPU A100 Space.
5
  """
6
  import gradio as gr
7
  import spaces
8
- import os
9
- import sys
10
- import subprocess
11
- import tempfile
12
 
13
- # ── One-time setup ──────────────────────────────────────────────────────────
14
  SADTALKER = "/tmp/SadTalker"
15
  CKPT = f"{SADTALKER}/checkpoints"
16
- GFPGAN = f"{SADTALKER}/gfpgan/weights"
17
 
18
  def _setup():
19
- if not os.path.exists(f"{CKPT}/SadTalker_V0.0.2_256.safetensors"):
20
- subprocess.run(["git", "clone", "--depth=1",
21
- "https://github.com/OpenTalker/SadTalker.git", SADTALKER], check=True)
22
- os.makedirs(CKPT, exist_ok=True)
23
- os.makedirs(GFPGAN, exist_ok=True)
24
- from huggingface_hub import hf_hub_download, snapshot_download
25
- snapshot_download("vinthony/SadTalker-V002rc", local_dir=CKPT, ignore_patterns=["*.md"])
26
- hf_hub_download("tencent/GFPGANv1.4", filename="GFPGANv1.4.pth",
27
- local_dir=GFPGAN)
28
- if SADTALKER not in sys.path:
29
- sys.path.insert(0, SADTALKER)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  _setup()
32
 
 
 
 
33
  from src.gradio_demo import SadTalker as _ST # noqa: E402
34
 
35
  _sad: _ST | None = None
@@ -43,14 +57,14 @@ def _load():
43
 
44
  @spaces.GPU
45
  def infer(source_image: str, driven_audio: str):
46
- """image filepath + audio filepath video filepath"""
47
  st = _load()
48
  result = st.test(
49
  source_image=source_image,
50
  driven_audio=driven_audio,
51
  preprocess="crop",
52
- still_mode=True,
53
- use_enhancer=False,
54
  batch_size=1,
55
  size=256,
56
  pose_style=0,
@@ -65,13 +79,17 @@ def infer(source_image: str, driven_audio: str):
65
  return result
66
 
67
 
68
- with gr.Blocks(title="AIBRUH/ditto Amanda Engine") as demo:
69
- gr.Markdown("## AIBRUH/ditto · Amanda Talking Head Engine")
70
  with gr.Row():
71
- img_in = gr.Image(type="filepath", label="Source Portrait")
72
  aud_in = gr.Audio(type="filepath", label="Driving Audio (WAV)")
73
- btn = gr.Button("Generate", variant="primary")
74
  vid_out = gr.Video(label="Amanda Speaking")
75
  btn.click(fn=infer, inputs=[img_in, aud_in], outputs=vid_out, api_name="infer")
 
 
 
 
76
 
77
  demo.launch()
 
1
  """
2
  AIBRUH/ditto — Amanda's talking head engine.
3
+ SadTalker ZeroGPU A100: portrait image + audio → MP4 talking head video.
 
4
  """
5
  import gradio as gr
6
  import spaces
7
+ import os, sys, subprocess, tempfile
 
 
 
8
 
 
9
  SADTALKER = "/tmp/SadTalker"
10
  CKPT = f"{SADTALKER}/checkpoints"
 
11
 
12
  def _setup():
13
+ if os.path.exists(f"{CKPT}/SadTalker_V0.0.2_256.safetensors"):
14
+ return # already done
15
+
16
+ # Clone SadTalker source
17
+ if not os.path.exists(SADTALKER):
18
+ subprocess.run(
19
+ ["git", "clone", "--depth=1",
20
+ "https://github.com/OpenTalker/SadTalker.git", SADTALKER],
21
+ check=True,
22
+ )
23
+
24
+ os.makedirs(CKPT, exist_ok=True)
25
+
26
+ # Download SadTalker checkpoints (no GFPGAN — we skip the enhancer)
27
+ from huggingface_hub import snapshot_download
28
+ snapshot_download(
29
+ repo_id="vinthony/SadTalker-V002rc",
30
+ local_dir=CKPT,
31
+ ignore_patterns=["*.md", "*.txt"],
32
+ )
33
+
34
+ # Install SadTalker deps that aren't in requirements.txt
35
+ subprocess.run(
36
+ [sys.executable, "-m", "pip", "install", "-q",
37
+ "face-alignment", "imageio", "imageio-ffmpeg",
38
+ "pydub", "scipy", "kornia==0.6.8", "basicsr"],
39
+ check=False,
40
+ )
41
 
42
  _setup()
43
 
44
+ if SADTALKER not in sys.path:
45
+ sys.path.insert(0, SADTALKER)
46
+
47
  from src.gradio_demo import SadTalker as _ST # noqa: E402
48
 
49
  _sad: _ST | None = None
 
57
 
58
  @spaces.GPU
59
  def infer(source_image: str, driven_audio: str):
60
+ """Portrait image + WAV audio → talking head MP4."""
61
  st = _load()
62
  result = st.test(
63
  source_image=source_image,
64
  driven_audio=driven_audio,
65
  preprocess="crop",
66
+ still_mode=True, # minimal head sway — portrait mode
67
+ use_enhancer=False, # no GFPGAN needed
68
  batch_size=1,
69
  size=256,
70
  pose_style=0,
 
79
  return result
80
 
81
 
82
+ with gr.Blocks(title="AIBRUH/ditto · Amanda Engine") as demo:
83
+ gr.Markdown("## AIBRUH/ditto · Amanda Talking Head Engine\n*SadTalker ZeroGPU — portrait image + audio → talking head video*")
84
  with gr.Row():
85
+ img_in = gr.Image(type="filepath", label="Source Portrait (JPG/PNG)")
86
  aud_in = gr.Audio(type="filepath", label="Driving Audio (WAV)")
87
+ btn = gr.Button("Generate Talking Head", variant="primary")
88
  vid_out = gr.Video(label="Amanda Speaking")
89
  btn.click(fn=infer, inputs=[img_in, aud_in], outputs=vid_out, api_name="infer")
90
+ gr.Examples(
91
+ examples=[],
92
+ inputs=[img_in, aud_in],
93
+ )
94
 
95
  demo.launch()