import os import subprocess import sys import gradio as gr # The URL of the GitHub repository to clone repo_url = "https://github.com/lvalics/roopapi.git" repo_dir = "roopapi" # Step 1: Clone the repository if it's not already present if not os.path.exists(repo_dir): print(f"Cloning the repository from {repo_url}...") subprocess.run(["git", "clone", repo_url]) # Step 2: Navigate to the 'roopapi' directory and install dependencies os.chdir(repo_dir) # Install dependencies from 'requirements.txt' in the repository print("Installing dependencies from requirements.txt...") subprocess.run(["pip", "install", "-r", "requirements.txt"]) # Step 3: Add the 'roopapi' directory to Python's module search path sys.path.append(os.path.join(os.getcwd(), repo_dir)) # Step 4: Import the ROOP module (from roopapi) try: from roop import ROOP # Importing the ROOP class from the roopapi repo print("ROOP module imported successfully.") except ModuleNotFoundError as e: print(f"Error importing the ROOP module: {e}") sys.exit(1) # Exit the script if ROOP is not found # Step 5: Initialize the ROOP model roop_model = ROOP() # Step 6: Define a Gradio interface function for face swapping def process_face_swap(image, video): # Use the ROOP model to swap faces print("Processing face swap...") output = roop_model.swap_faces(image, video) return output # Step 7: Create a Gradio interface for the app iface = gr.Interface( fn=process_face_swap, inputs=["image", "video"], # Image and video inputs outputs="video", # The output will be a video live=True, title="ROOP Face Swapping", description="Upload an image and a video to swap faces using the ROOP model." ) # Step 8: Launch the Gradio interface if __name__ == "__main__": iface.launch()