multimodalart HF staff commited on
Commit
59d9186
1 Parent(s): 751c5b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -2,46 +2,38 @@ import os
2
  import shutil
3
  from huggingface_hub import snapshot_download
4
  import gradio as gr
 
5
  from scripts.inference import inference_process
6
  import argparse
 
7
 
8
- # Download the repository contents into a directory
9
- hallo_dir = snapshot_download(repo_id="fudan-generative-ai/hallo")
10
-
11
- # Define the new directory path for the pretrained models
12
- new_dir = 'pretrained_models'
13
-
14
- # Ensure the new directory exists
15
- os.makedirs(new_dir, exist_ok=True)
16
-
17
- # Move all contents from the downloaded directory to the new directory
18
- for filename in os.listdir(hallo_dir):
19
- shutil.move(os.path.join(hallo_dir, filename), os.path.join(new_dir, filename))
20
 
21
  def run_inference(source_image, driving_audio, progress=gr.Progress(track_tqdm=True)):
22
- # Construct the argparse.Namespace object with all necessary attributes
 
23
  args = argparse.Namespace(
24
- config='configs/inference/default.yaml', # Adjust this path as necessary
25
  source_image=source_image,
26
  driving_audio=driving_audio,
27
- output='output.mp4', # You might want to manage output paths dynamically
28
  pose_weight=1.0,
29
  face_weight=1.0,
30
  lip_weight=1.0,
31
  face_expand_ratio=1.2,
32
- checkpoint=None # Adjust or set this according to your checkpointing strategy
33
  )
34
 
35
- # Call the imported function
36
  inference_process(args)
37
-
38
- # Return output or path to output
39
- return 'output.mp4' # Modify based on your output handling
40
 
41
  iface = gr.Interface(
 
 
42
  fn=run_inference,
43
  inputs=[gr.Image(type="filepath"), gr.Audio(type="filepath")],
 
44
  outputs="video"
45
  )
46
 
47
- iface.launch()
 
2
  import shutil
3
  from huggingface_hub import snapshot_download
4
  import gradio as gr
5
+ os.chdir(os.path.dirname(os.path.abspath(__file__)))
6
  from scripts.inference import inference_process
7
  import argparse
8
+ import uuid
9
 
10
+ hallo_dir = snapshot_download(repo_id="fudan-generative-ai/hallo", local_dir="pretrained_models")
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  def run_inference(source_image, driving_audio, progress=gr.Progress(track_tqdm=True)):
13
+ unique_id = uuid.uuid4()
14
+
15
  args = argparse.Namespace(
16
+ config='configs/inference/default.yaml',
17
  source_image=source_image,
18
  driving_audio=driving_audio,
19
+ output=f'output-{unique_id}.mp4',
20
  pose_weight=1.0,
21
  face_weight=1.0,
22
  lip_weight=1.0,
23
  face_expand_ratio=1.2,
24
+ checkpoint=None
25
  )
26
 
 
27
  inference_process(args)
28
+ return f'output-{unique_id}.mp4'
 
 
29
 
30
  iface = gr.Interface(
31
+ title="Demo for Hallo: Hierarchical Audio-Driven Visual Synthesis for Portrait Image Animation",
32
+ description="Generate talking head avatars driven from audio. **every 10 seconds of generation takes ~1 minute** - duplicate the space for private use or try for free on Google Colab",
33
  fn=run_inference,
34
  inputs=[gr.Image(type="filepath"), gr.Audio(type="filepath")],
35
+ cache_examples=False,
36
  outputs="video"
37
  )
38
 
39
+ iface.launch(share=True)