Spaces:
Running
on
Zero
Running
on
Zero
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
import tempfile
|
| 5 |
+
from glob import glob
|
| 6 |
+
|
| 7 |
+
def run_inference(image_input, audio_input):
|
| 8 |
+
|
| 9 |
+
# Create a temporary folder for downloaded and processed images
|
| 10 |
+
temp_dir = tempfile.mkdtemp()
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
# Run the inference command
|
| 14 |
+
python inference.py --config configs/inference.yaml --input_image <IMAGE_PATH> --input_audio <AUDIO_PATH> --output_dir <SAVE_PATH>
|
| 15 |
+
|
| 16 |
+
subprocess.run(
|
| 17 |
+
[
|
| 18 |
+
"python", "inference.py",
|
| 19 |
+
"--config", "configs/inference.yaml",
|
| 20 |
+
f"input_image={image_input}",
|
| 21 |
+
f"input_audio={audio_input}",
|
| 22 |
+
f"output_dir={temp_dir}",
|
| 23 |
+
],
|
| 24 |
+
check=True
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Collect the output images
|
| 28 |
+
output_video = glob(os.path.join(temp_dir, "*.mp4"))
|
| 29 |
+
return output_video[0]
|
| 30 |
+
except subprocess.CalledProcessError as e:
|
| 31 |
+
raise gr.Error(f"Error during inference: {str(e)}")
|
| 32 |
+
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
with gr.Column():
|
| 35 |
+
gr.Markdown("# MEMO")
|
| 36 |
+
with gr.Row():
|
| 37 |
+
with gr.Column():
|
| 38 |
+
image_input = gr.Image(label="Image Input", type="filepath")
|
| 39 |
+
audio_input = gr.Audio(label="Audio Input")
|
| 40 |
+
submit_btn = gr.Button("Submit")
|
| 41 |
+
with gr.Column():
|
| 42 |
+
output_result = gr.Video(label="Result")
|
| 43 |
+
|
| 44 |
+
submit_btn.click(
|
| 45 |
+
fn =run_inference,
|
| 46 |
+
inputs =[image_input, audio_input],
|
| 47 |
+
outputs = [output_result]
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
demo.queue().launch()
|