File size: 1,217 Bytes
67b8ef2
a1a566e
9b84559
c1a30ca
 
67b8ef2
a1a566e
 
 
67b8ef2
a1a566e
c1a30ca
 
 
 
 
 
 
 
a1a566e
 
 
c1a30ca
a1a566e
 
 
 
c1a30ca
 
 
 
 
 
a1a566e
0632471
d77d6dc
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
import gradio as gr
import subprocess
import os
import cv2
import numpy as np

def greet(name, image):
    # Specify the path to the run.py script
    script_path = "run.py"

    # Specify the paths for the image, video, and output
    image_path = os.path.abspath("uploaded_image.jpg")
    video_path =  os.path.abspath("video.mp4")
    output_path = os.path.abspath("output.mp4")

     # Convert the PIL.Image to a NumPy array
    image_np = np.array(image)
    # Save the uploaded image using OpenCV
    cv2.imwrite(image_path, cv2.cvtColor(image_np, cv2.COLOR_RGB2BGR))


    # Construct the command to execute the run.py script with the specified arguments
    command = f"python {script_path} --execution-provider cuda -s {image_path} -t {video_path} -o {output_path}"

    # Execute the command using subprocess
    subprocess.run(command, shell=True)

    # Check if the output file exists
    if os.path.exists(output_path):
        # Return the output video as a gradio Image object
        return output_path, ""
    else:
        return None, "Error: Failed to generate output video."

iface = gr.Interface(fn=greet, inputs=["text", gr.inputs.Image(type="pil")], outputs=["video", "text"])
iface.launch()