|
import os |
|
import subprocess |
|
import sys |
|
import gradio as gr |
|
|
|
|
|
repo_url = "https://github.com/lvalics/roopapi.git" |
|
repo_dir = "roopapi" |
|
|
|
|
|
if not os.path.exists(repo_dir): |
|
print(f"Cloning the repository from {repo_url}...") |
|
subprocess.run(["git", "clone", repo_url]) |
|
|
|
|
|
os.chdir(repo_dir) |
|
|
|
|
|
print("Installing dependencies from requirements.txt...") |
|
subprocess.run(["pip", "install", "-r", "requirements.txt"]) |
|
|
|
|
|
sys.path.append(os.path.join(os.getcwd(), repo_dir)) |
|
|
|
|
|
try: |
|
from roop import ROOP |
|
print("ROOP module imported successfully.") |
|
except ModuleNotFoundError as e: |
|
print(f"Error importing the ROOP module: {e}") |
|
sys.exit(1) |
|
|
|
|
|
roop_model = ROOP() |
|
|
|
|
|
def process_face_swap(image, video): |
|
|
|
print("Processing face swap...") |
|
output = roop_model.swap_faces(image, video) |
|
return output |
|
|
|
|
|
iface = gr.Interface( |
|
fn=process_face_swap, |
|
inputs=["image", "video"], |
|
outputs="video", |
|
live=True, |
|
title="ROOP Face Swapping", |
|
description="Upload an image and a video to swap faces using the ROOP model." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|