insanecoder69 commited on
Commit
d6fcce5
·
verified ·
1 Parent(s): ff94b89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -57
app.py CHANGED
@@ -1,70 +1,41 @@
1
  import gradio as gr
2
  import subprocess
3
  import os
4
- from pydub import AudioSegment
5
- import tempfile
6
 
7
- # Set OpenGL platform
8
- os.environ["PYOPENGL_PLATFORM"] = "egl"
9
- os.environ["MESA_GL_VERSION_OVERRIDE"] = "4.1"
10
- os.system('pip install /home/user/app/pyrender')
11
 
12
- # Paths to TalkShow demo script and configuration
13
- DEMO_SCRIPT_PATH = "scripts/demo.py"
14
- CONFIG_FILE = "./config/LS3DCG.json"
15
- BODY_MODEL_PATH = "experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth"
16
- OUTPUT_MP4_PATH = "./output/demo_output.mp4"
 
17
 
18
- # Ensure the output directory exists
19
- os.makedirs(os.path.dirname(OUTPUT_MP4_PATH), exist_ok=True)
 
20
 
21
- def convert_audio_to_wav(input_audio):
22
- # Use a temporary file to save the .wav output
23
- temp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
24
- temp_wav_path = temp_wav.name
25
 
26
- # Convert the input audio to .wav format
27
- audio = AudioSegment.from_file(input_audio)
28
- audio.export(temp_wav_path, format="wav")
29
- return temp_wav_path
 
30
 
31
- def run_demo_and_get_video(input_audio):
32
- # Convert the input audio to a temporary .wav file
33
- wav_path = convert_audio_to_wav(input_audio)
34
 
35
- try:
36
- # Run the demo script with the specified arguments
37
- command = [
38
- "python", DEMO_SCRIPT_PATH,
39
- "--config_file", CONFIG_FILE,
40
- "--infer",
41
- "--audio_file", wav_path,
42
- "--body_model_name", "s2g_LS3DCG",
43
- "--body_model_path", BODY_MODEL_PATH,
44
- "--id", "0"
45
- ]
46
- subprocess.run(command, check=True)
47
-
48
- # Check if the output file exists
49
- if os.path.exists(OUTPUT_MP4_PATH):
50
- return OUTPUT_MP4_PATH
51
- else:
52
- return "Error: Output video not generated."
53
- except subprocess.CalledProcessError as e:
54
- return f"Error: {str(e)}"
55
- finally:
56
- # Clean up the temporary .wav file after processing
57
- os.remove(wav_path)
58
-
59
- # Define the Gradio interface
60
  interface = gr.Interface(
61
- fn=run_demo_and_get_video,
62
- inputs=gr.Audio(source="upload", type="filepath"),
63
- outputs=gr.Video(type="file"),
64
- title="TalkSHOW Demo",
65
- description="Generate a video from audio input using TalkSHOW model."
66
  )
67
 
68
- # Launch the app
69
- if __name__ == "__main__":
70
- interface.launch()
 
1
  import gradio as gr
2
  import subprocess
3
  import os
 
 
4
 
5
+ # Define the command template
6
+ COMMAND_TEMPLATE = "python scripts/demo.py --config_file ./config/LS3DCG.json --infer --audio_file {audio_path} --body_model_name s2g_LS3DCG --body_model_path experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth --id 0"
 
 
7
 
8
+ # Define the function to process the audio and generate the video
9
+ def process_audio(audio):
10
+ # Save uploaded audio to a specific file path
11
+ audio_path = "demo_audio/style.wav"
12
+ with open(audio_path, "wb") as f:
13
+ f.write(audio.read())
14
 
15
+ # Run the script command with the specified audio file
16
+ command = COMMAND_TEMPLATE.format(audio_path=audio_path)
17
+ subprocess.run(command, shell=True)
18
 
19
+ # Specify the path to the output video
20
+ output_video_path = "./output_video.mp4" # Update if output location is different
 
 
21
 
22
+ # Check if the video file exists and return it for display
23
+ if os.path.exists(output_video_path):
24
+ return output_video_path
25
+ else:
26
+ return "Error: Video file not generated."
27
 
28
+ # Set up Gradio interface
29
+ audio_input = gr.Audio(label="Upload a .wav audio file", type="file")
30
+ video_output = gr.Video(label="Generated Video Output")
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  interface = gr.Interface(
33
+ fn=process_audio,
34
+ inputs=audio_input,
35
+ outputs=video_output,
36
+ title="Audio-to-Video Generator",
37
+ description="Upload a .wav file to generate an animated video output."
38
  )
39
 
40
+ # Launch the Gradio app
41
+ interface.launch()