Madras1 commited on
Commit
fe0a2e1
·
verified ·
1 Parent(s): f4d455b

Upload 3 files

Browse files
Files changed (2) hide show
  1. README.md +4 -5
  2. app.py +47 -29
README.md CHANGED
@@ -9,15 +9,14 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- # SadTalker API 🎭
13
 
14
- Talking head generation using SadTalker with **ZeroGPU**.
15
 
16
  ## Features
17
- - GPU-accelerated (~20-40 seconds)
18
- - 🎨 Face enhancement with GFPGAN
19
  - 📹 Returns MP4 video
20
 
21
  ## Usage
22
-
23
  Upload a face image and audio file, click Generate.
 
9
  pinned: false
10
  ---
11
 
12
+ # SadTalker API (CPU) 🎭
13
 
14
+ Talking head generation using SadTalker in **CPU mode**.
15
 
16
  ## Features
17
+ - 🐢 Runs on CPU (2-5 min per video)
18
+ - ♾️ No quota limits
19
  - 📹 Returns MP4 video
20
 
21
  ## Usage
 
22
  Upload a face image and audio file, click Generate.
app.py CHANGED
@@ -82,46 +82,64 @@ def generate_video_gpu(image_path: str, audio_path: str, output_dir: str) -> str
82
 
83
  def gradio_generate(image, audio):
84
  """Gradio interface wrapper"""
85
- if image is None or audio is None:
86
- raise gr.Error("Por favor, envie uma imagem e um áudio")
 
 
 
 
 
 
 
 
87
 
88
  with tempfile.TemporaryDirectory() as tmpdir:
89
- # Save uploaded files
90
  image_path = os.path.join(tmpdir, "input.png")
91
  audio_path = os.path.join(tmpdir, "input.wav")
92
  output_dir = os.path.join(tmpdir, "output")
93
  os.makedirs(output_dir, exist_ok=True)
94
 
95
- # Handle image - Gradio gives filepath
96
- if isinstance(image, str):
97
- shutil.copy(image, image_path)
98
- else:
99
- from PIL import Image
100
- if hasattr(image, 'save'):
101
- image.save(image_path)
102
  else:
103
- Image.fromarray(image).save(image_path)
104
-
105
- # Handle audio - Gradio gives filepath
106
- if isinstance(audio, str):
107
- shutil.copy(audio, audio_path)
108
- elif isinstance(audio, tuple):
109
- # (sample_rate, audio_data) format
110
- import scipy.io.wavfile as wav
111
- sr, data = audio
112
- wav.write(audio_path, sr, data)
113
 
114
- print(f"Image: {image_path}, exists: {os.path.exists(image_path)}")
115
- print(f"Audio: {audio_path}, exists: {os.path.exists(audio_path)}")
116
-
117
- # Generate video with GPU
118
- video_path = generate_video_gpu(image_path, audio_path, output_dir)
 
 
 
 
 
 
 
 
 
119
 
120
- # Copy to persistent location for Gradio
121
- final_path = "/tmp/sadtalker_output.mp4"
122
- shutil.copy(video_path, final_path)
123
 
124
- return final_path
 
 
 
 
 
 
 
 
 
 
125
 
126
  # Create Gradio app
127
  with gr.Blocks(title="SadTalker API") as demo:
 
82
 
83
  def gradio_generate(image, audio):
84
  """Gradio interface wrapper"""
85
+ # Debug logging
86
+ print(f"=== RECEIVED ===")
87
+ print(f"Image type: {type(image)}, value: {image}")
88
+ print(f"Audio type: {type(audio)}, value: {audio}")
89
+
90
+ # Better validation
91
+ if not image:
92
+ raise gr.Error("Envie uma imagem primeiro!")
93
+ if not audio:
94
+ raise gr.Error("Envie um áudio primeiro!")
95
 
96
  with tempfile.TemporaryDirectory() as tmpdir:
 
97
  image_path = os.path.join(tmpdir, "input.png")
98
  audio_path = os.path.join(tmpdir, "input.wav")
99
  output_dir = os.path.join(tmpdir, "output")
100
  os.makedirs(output_dir, exist_ok=True)
101
 
102
+ # Handle image
103
+ try:
104
+ if isinstance(image, str) and os.path.exists(image):
105
+ shutil.copy(image, image_path)
106
+ elif hasattr(image, 'name'): # File object
107
+ shutil.copy(image.name, image_path)
 
108
  else:
109
+ from PIL import Image as PILImage
110
+ PILImage.fromarray(image).save(image_path)
111
+ except Exception as e:
112
+ raise gr.Error(f"Erro ao processar imagem: {e}")
 
 
 
 
 
 
113
 
114
+ # Handle audio
115
+ try:
116
+ if isinstance(audio, str) and os.path.exists(audio):
117
+ shutil.copy(audio, audio_path)
118
+ elif hasattr(audio, 'name'): # File object
119
+ shutil.copy(audio.name, audio_path)
120
+ elif isinstance(audio, tuple):
121
+ import scipy.io.wavfile as wav
122
+ sr, data = audio
123
+ wav.write(audio_path, sr, data)
124
+ else:
125
+ raise gr.Error(f"Formato de áudio não reconhecido: {type(audio)}")
126
+ except Exception as e:
127
+ raise gr.Error(f"Erro ao processar áudio: {e}")
128
 
129
+ print(f"Image saved: {image_path}, exists: {os.path.exists(image_path)}")
130
+ print(f"Audio saved: {audio_path}, exists: {os.path.exists(audio_path)}")
 
131
 
132
+ # Generate video
133
+ try:
134
+ video_path = generate_video_gpu(image_path, audio_path, output_dir)
135
+
136
+ # Copy to persistent location
137
+ final_path = "/tmp/sadtalker_output.mp4"
138
+ shutil.copy(video_path, final_path)
139
+
140
+ return final_path
141
+ except Exception as e:
142
+ raise gr.Error(f"Erro na geração: {e}")
143
 
144
  # Create Gradio app
145
  with gr.Blocks(title="SadTalker API") as demo: