Spaces:
Paused
Paused
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() | |