insanecoder69 commited on
Commit
195b61e
·
verified ·
1 Parent(s): a40e0c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -48
app.py CHANGED
@@ -1,57 +1,83 @@
1
- import gradio as gr
2
- import subprocess
3
  import os
4
  import sys
5
- os.environ["PYOPENGL_PLATFORM"] = "egl"
 
 
 
 
 
 
 
 
6
 
7
- def run_talkshow_model(audio_file):
8
- # Path to the TalkSHOW demo script
9
- demo_script = 'scripts/demo.py'
10
-
11
- # Configuration and model parameters
12
- config_file = './config/LS3DCG.json'
13
- body_model_name = 's2g_LS3DCG'
14
- body_model_path = 'experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth'
15
-
16
- # Path of the uploaded audio file
17
- audio_file_path = audio_file
18
-
19
- # Path where the output .mp4 video will be saved
20
- output_video_path = './visualise/result.mp4'
21
 
22
- # Run the demo.py script with the necessary arguments
23
- command = [
24
- 'python', demo_script,
25
- '--config_file', config_file,
26
- '--infer',
27
- '--audio_file', audio_file_path,
28
- '--body_model_name', body_model_name,
29
- '--body_model_path', body_model_path,
30
- '--id', '0',
31
- '--output', output_video_path
32
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- try:
35
- # Run the subprocess and capture output
36
- subprocess.run(command, check=True, capture_output=True, text=True)
37
-
38
- # Check if the .mp4 file is generated
39
- if os.path.exists(output_video_path):
40
- return output_video_path # Return the path of the generated video
41
- else:
42
- return "Error: Output video not generated."
 
 
 
43
 
44
- except subprocess.CalledProcessError as e:
45
- return f"Error running the model: {e.stderr}" # Return the error message
46
-
47
- # Set up the Gradio interface
48
- interface = gr.Interface(
49
- fn=run_talkshow_model,
50
- inputs=gr.Audio(source="upload", type="filepath"),
51
- outputs=gr.Video(), # Use gr.Video to output the generated .mp4 video
52
- title="TalkSHOW: Audio to Mesh"
 
 
 
 
 
 
 
 
53
  )
54
 
55
- # Launch the interface
56
  if __name__ == "__main__":
57
- interface.launch()
 
 
 
1
  import os
2
  import sys
3
+ import gradio as gr
4
+ import torch
5
+ import numpy as np
6
+ from transformers import Wav2Vec2Processor
7
+ from visualise.rendering import RenderTool
8
+ from data_utils import torch_data
9
+ from trainer.options import parse_args
10
+ from trainer.config import load_JsonConfig
11
+ from nets import init_model, infer # Ensure these functions are properly defined
12
 
13
+ # Set environment variables
14
+ os.environ['PYOPENGL_PLATFORM'] = 'egl'
15
+ os.environ['CUDA_VISIBLE_DEVICES'] = '0'
16
+ sys.path.append(os.getcwd())
17
+
18
+ # Load the model and configuration
19
+ def load_models(config_file, face_model_name, face_model_path, body_model_name, body_model_path):
20
+ args = parse_args()
21
+ config = load_JsonConfig(config_file)
 
 
 
 
 
22
 
23
+ # Initialize models
24
+ generator_face = init_model(face_model_name, face_model_path, args, config)
25
+ generator_body = init_model(body_model_name, body_model_path, args, config)
26
+
27
+ # Initialize SMPL-X model
28
+ smplx_model_params = {
29
+ 'model_path': './visualise/',
30
+ 'model_type': 'smplx',
31
+ 'create_global_orient': True,
32
+ 'create_body_pose': True,
33
+ 'create_betas': True,
34
+ 'num_betas': 300,
35
+ 'create_left_hand_pose': True,
36
+ 'create_right_hand_pose': True,
37
+ 'use_pca': False,
38
+ 'flat_hand_mean': False,
39
+ 'create_expression': True,
40
+ 'num_expression_coeffs': 100,
41
+ 'num_pca_comps': 12,
42
+ 'create_jaw_pose': True,
43
+ 'create_leye_pose': True,
44
+ 'create_reye_pose': True,
45
+ 'create_transl': False,
46
+ 'dtype': torch.float64,
47
+ }
48
+ smplx_model = smpl.create(**smplx_model_params).to('cuda')
49
 
50
+ return generator_face, generator_body, smplx_model, config
51
+
52
+ # Inference function
53
+ def run_inference(audio_file):
54
+ # Load models
55
+ generator_face, generator_body, smplx_model, config = load_models(
56
+ './config/LS3DCG.json',
57
+ 's2g_LS3DCG',
58
+ 'experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth',
59
+ 's2g_LS3DCG',
60
+ 'experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth'
61
+ )
62
 
63
+ # Initialize rendering tool
64
+ rendertool = RenderTool('visualise/video/' + config.Log.name)
65
+
66
+ # Inference
67
+ infer(generator_body, generator_face, smplx_model, rendertool, config, audio_file)
68
+
69
+ # Provide output (e.g., path to the rendered video)
70
+ output_video_path = f'visualise/video/{config.Log.name}/{audio_file.split("/")[-1].split(".")[0]}.npy'
71
+ return output_video_path
72
+
73
+ # Gradio interface
74
+ iface = gr.Interface(
75
+ fn=run_inference,
76
+ inputs=gr.inputs.Audio(source="upload", type="filepath", label="Upload Audio File"),
77
+ outputs=gr.outputs.Textbox(label="Output Video Path"),
78
+ title="Audio to 3D Model Renderer",
79
+ description="Upload an audio file to generate a 3D model rendering."
80
  )
81
 
 
82
  if __name__ == "__main__":
83
+ iface.launch()