multimodalart HF staff commited on
Commit
63f899c
1 Parent(s): 391648c

Create app.py (#1)

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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, 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.name,
26
+ driving_audio=driving_audio.name,
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.inputs.Image(type="file"), gr.inputs.Audio(type="file")],
44
+ outputs="text"
45
+ )
46
+
47
+ iface.launch()