Spaces:
Running
on
Zero
Running
on
Zero
| import gradio as gr | |
| import os | |
| import subprocess | |
| import tempfile | |
| from glob import glob | |
| def run_inference(image_input, audio_input): | |
| # Create a temporary folder for downloaded and processed images | |
| temp_dir = tempfile.mkdtemp() | |
| try: | |
| # Run the inference command | |
| subprocess.run( | |
| [ | |
| "python", "inference.py", | |
| "--config", "configs/inference.yaml", | |
| "--input_image", image_input, | |
| "--input_audio", audio_input, | |
| "--output_dir", temp_dir, | |
| ], | |
| check=True | |
| ) | |
| # Collect the output images | |
| output_video = glob(os.path.join(temp_dir, "*.mp4")) | |
| return output_video[0] | |
| except subprocess.CalledProcessError as e: | |
| raise gr.Error(f"Error during inference: {str(e)}") | |
| with gr.Blocks() as demo: | |
| with gr.Column(): | |
| gr.Markdown("# MEMO") | |
| with gr.Row(): | |
| with gr.Column(): | |
| image_input = gr.Image(label="Image Input", type="filepath") | |
| audio_input = gr.Audio(label="Audio Input", type="filepath") | |
| submit_btn = gr.Button("Submit") | |
| with gr.Column(): | |
| output_result = gr.Video(label="Result") | |
| submit_btn.click( | |
| fn =run_inference, | |
| inputs =[image_input, audio_input], | |
| outputs = [output_result] | |
| ) | |
| demo.queue().launch() | |