File size: 2,110 Bytes
a935d95
 
 
 
 
 
5c21044
a935d95
 
 
 
 
4bdb3a5
 
a935d95
 
 
d043cd2
 
 
a935d95
4bdb3a5
 
 
a935d95
 
4bdb3a5
 
 
 
 
 
 
 
 
 
 
a935d95
4bdb3a5
 
 
a935d95
 
4bdb3a5
a935d95
 
 
 
 
 
5195ba0
a935d95
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
import os 
import subprocess
import tempfile
from glob import glob

def run_inference(image_input, audio_input, progress=gr.Progress(track_tqdm=True)):

    # Create a temporary folder for downloaded and processed images
    temp_dir = tempfile.mkdtemp()

    try:
        # Start the subprocess with Popen to capture logs
        process = subprocess.Popen(
            [
                "python", "inference.py",
                "--config", "configs/inference.yaml",
                "--input_image", image_input,
                "--input_audio", audio_input,
                "--output_dir", temp_dir,
            ],
            stdout=subprocess.PIPE,  # Capture standard output
            stderr=subprocess.PIPE,  # Capture standard error
            text=True,  # Decode output to text (instead of bytes)
        )

        # Stream logs from the subprocess in real-time
        for line in process.stdout:
            print(line, end="")  # Print logs to the console (or handle them as needed)

        # Wait for the subprocess to finish and check for errors
        process.wait()
        if process.returncode != 0:
            error_message = process.stderr.read()
            raise gr.Error(f"Inference failed with error: {error_message}")

        # Collect the output video
        output_video = glob(os.path.join(temp_dir, "*.mp4"))
        return output_video[0] if output_video else "No video generated."

    except Exception 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()