import os import subprocess import gradio as gr # Clone the GitHub repository if not os.path.exists("roopapi"): subprocess.run(["git", "clone", "https://github.com/lvalics/roopapi.git"]) # Change the working directory to the cloned repository os.chdir("roopapi") # Install the required dependencies from requirements.txt (if it's not already installed) subprocess.run(["pip", "install", "-r", "requirements.txt"]) # Now import the ROOP API (assuming `roop.py` is in the cloned repo) from roop import ROOP # Initialize ROOP model roop_model = ROOP() # Gradio function to swap faces def process_face_swap(image, video): output = roop_model.swap_faces(image, video) return output # Gradio interface iface = gr.Interface( fn=process_face_swap, inputs=["image", "video"], outputs="video", live=True, title="ROOP Face Swapping API", description="Upload an image and a video to swap faces." ) iface.launch()