fffiloni commited on
Commit
b4f123a
·
verified ·
1 Parent(s): fc29ff5

add ZeroGPU decorations

Browse files
Files changed (1) hide show
  1. webgui.py +32 -30
webgui.py CHANGED
@@ -4,6 +4,7 @@
4
  webui
5
  '''
6
 
 
7
  import os
8
  import random
9
  from datetime import datetime
@@ -252,6 +253,36 @@ def process_video(uploaded_img, uploaded_audio, width, height, length, seed, fac
252
 
253
  return final_output_path
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  def get_maskGCT_TTS(prompt_audio_maskGCT, audio_to_clone):
256
  try:
257
  client = Client("amphion/maskgct")
@@ -356,36 +387,7 @@ with gr.Blocks() as demo:
356
  <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/follow-me-on-HF-xl-dark.svg" alt="Follow me on HF">
357
  </a>
358
  </div>
359
- """)
360
-
361
- def trim_audio(file_path, output_path, max_duration=10):
362
- # Load the audio file
363
- audio = AudioSegment.from_wav(file_path)
364
-
365
- # Convert max duration to milliseconds
366
- max_duration_ms = max_duration * 1000
367
-
368
- # Trim the audio if it's longer than max_duration
369
- if len(audio) > max_duration_ms:
370
- audio = audio[:max_duration_ms]
371
-
372
- # Export the trimmed audio
373
- audio.export(output_path, format="wav")
374
- print(f"Audio trimmed and saved as {output_path}")
375
- return output_path
376
-
377
- def generate_video(uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device, progress=gr.Progress(track_tqdm=True)):
378
- if is_shared_ui:
379
- gr.Info("Trimming audio to max 10 seconds. Duplicate the space for unlimited audio length.")
380
- uploaded_audio = trim_audio(uploaded_audio, "trimmed_audio.wav")
381
-
382
-
383
-
384
- final_output_path = process_video(
385
- uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device
386
- )
387
- output_video= final_output_path
388
- return final_output_path
389
 
390
  gen_maskGCT_voice_btn.click(
391
  fn = get_maskGCT_TTS,
 
4
  webui
5
  '''
6
 
7
+ import spaces
8
  import os
9
  import random
10
  from datetime import datetime
 
253
 
254
  return final_output_path
255
 
256
+ def trim_audio(file_path, output_path, max_duration=10):
257
+ # Load the audio file
258
+ audio = AudioSegment.from_wav(file_path)
259
+
260
+ # Convert max duration to milliseconds
261
+ max_duration_ms = max_duration * 1000
262
+
263
+ # Trim the audio if it's longer than max_duration
264
+ if len(audio) > max_duration_ms:
265
+ audio = audio[:max_duration_ms]
266
+
267
+ # Export the trimmed audio
268
+ audio.export(output_path, format="wav")
269
+ print(f"Audio trimmed and saved as {output_path}")
270
+ return output_path
271
+
272
+ @spaces.GPU(duration=300)
273
+ def generate_video(uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device, progress=gr.Progress(track_tqdm=True)):
274
+ if is_shared_ui:
275
+ gr.Info("Trimming audio to max 10 seconds. Duplicate the space for unlimited audio length.")
276
+ uploaded_audio = trim_audio(uploaded_audio, "trimmed_audio.wav")
277
+
278
+
279
+
280
+ final_output_path = process_video(
281
+ uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device
282
+ )
283
+ output_video= final_output_path
284
+ return final_output_path
285
+
286
  def get_maskGCT_TTS(prompt_audio_maskGCT, audio_to_clone):
287
  try:
288
  client = Client("amphion/maskgct")
 
387
  <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/follow-me-on-HF-xl-dark.svg" alt="Follow me on HF">
388
  </a>
389
  </div>
390
+ """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
 
392
  gen_maskGCT_voice_btn.click(
393
  fn = get_maskGCT_TTS,