File size: 1,812 Bytes
2c47632
b5bcc75
ee71b69
b5bcc75
 
ee71b69
b1d1c6f
 
b5bcc75
6631944
b1d1c6f
ee71b69
b1d1c6f
b5bcc75
6631944
b1d1c6f
ee71b69
6631944
ee71b69
b5bcc75
 
6631944
ee71b69
 
6631944
ee71b69
6631944
ee71b69
 
6631944
 
2c47632
6631944
2c47632
 
6631944
2c47632
6631944
ee71b69
2c47632
 
 
6631944
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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()