Spaces:
Sleeping
Sleeping
import gradio as gr | |
import subprocess | |
import os | |
import json | |
def get_log_name(config_file): | |
"""Load the JSON configuration file to extract the log name.""" | |
with open(config_file, 'r') as f: | |
config = json.load(f) | |
return config['Log']['name'] # Adjust this if the structure is different | |
def run_inference(audio_file): | |
# Extract the audio filename | |
audio_filename = os.path.basename(audio_file) | |
# Load the configuration to get the log name | |
config_file = './config/LS3DCG.json' | |
config_log_name = get_log_name(config_file) | |
# Define the command to run your script | |
command = [ | |
"python", "scripts/demo.py", | |
"--config_file", config_file, | |
"--infer", | |
"--audio_file", audio_file, | |
"--body_model_name", "s2g_LS3DCG", | |
"--body_model_path", "experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth", | |
"--id", "0" | |
] | |
# Run the command and capture the output | |
result = subprocess.run(command, capture_output=True, text=True) | |
# Check for errors | |
if result.returncode != 0: | |
return f"Error: {result.stderr}" | |
# Construct the output video filename based on the log name | |
output_video_path = f'visualise/video/{config_log_name}/{audio_filename.rsplit(".", 1)[0]}.mp4' | |
# Check if the video file exists and return the path | |
if os.path.exists(output_video_path): | |
return output_video_path | |
else: | |
return "Video file not found." | |
# Create Gradio interface | |
interface = gr.Interface( | |
fn=run_inference, | |
inputs=gr.Audio(source="upload", type="filepath"), | |
outputs=gr.Video(type="file"), | |
title="Audio to Video Inference", | |
description="Upload an audio file to generate a video." | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
interface.launch() | |