Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,45 @@
|
|
1 |
import os
|
2 |
import subprocess
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
-
#
|
6 |
repo_url = "https://github.com/lvalics/roopapi.git"
|
7 |
repo_dir = "roopapi"
|
8 |
|
|
|
9 |
if not os.path.exists(repo_dir):
|
|
|
10 |
subprocess.run(["git", "clone", repo_url])
|
11 |
|
12 |
-
# Install
|
13 |
-
#
|
14 |
os.chdir(repo_dir)
|
|
|
|
|
|
|
15 |
subprocess.run(["pip", "install", "-r", "requirements.txt"])
|
16 |
|
17 |
-
#
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
# Initialize the ROOP
|
21 |
roop_model = ROOP()
|
22 |
|
23 |
-
# Define a
|
24 |
def process_face_swap(image, video):
|
|
|
|
|
25 |
output = roop_model.swap_faces(image, video)
|
26 |
return output
|
27 |
|
28 |
-
# Create
|
29 |
-
iface = gr.
|
30 |
-
fn=process_face_swap,
|
31 |
-
inputs=["image", "video"],
|
32 |
-
outputs="video",
|
33 |
-
live=True,
|
34 |
-
title="ROOP Face Swapping API",
|
35 |
-
description="Upload an image and a video to swap faces."
|
36 |
-
)
|
37 |
-
|
38 |
-
iface.launch()
|
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
+
import sys
|
4 |
import gradio as gr
|
5 |
|
6 |
+
# The URL of the GitHub repository to clone
|
7 |
repo_url = "https://github.com/lvalics/roopapi.git"
|
8 |
repo_dir = "roopapi"
|
9 |
|
10 |
+
# Step 1: Clone the GitHub repository if it's not already present
|
11 |
if not os.path.exists(repo_dir):
|
12 |
+
print(f"Cloning the repository from {repo_url}...")
|
13 |
subprocess.run(["git", "clone", repo_url])
|
14 |
|
15 |
+
# Step 2: Install the necessary dependencies from the repository's requirements.txt
|
16 |
+
# Ensure that we are in the correct directory before running pip install
|
17 |
os.chdir(repo_dir)
|
18 |
+
|
19 |
+
# Installing the dependencies defined in the repository's requirements.txt
|
20 |
+
print("Installing dependencies from requirements.txt...")
|
21 |
subprocess.run(["pip", "install", "-r", "requirements.txt"])
|
22 |
|
23 |
+
# Step 3: Add the repository to Python's path to access the `roop` module
|
24 |
+
sys.path.append(os.path.join(os.getcwd(), repo_dir))
|
25 |
+
|
26 |
+
# Step 4: Import the ROOP class from the `roop` module
|
27 |
+
try:
|
28 |
+
from roop import ROOP
|
29 |
+
print("ROOP module imported successfully.")
|
30 |
+
except ModuleNotFoundError as e:
|
31 |
+
print("Error importing the ROOP module:", e)
|
32 |
+
sys.exit(1)
|
33 |
|
34 |
+
# Initialize the ROOP model (this might take time depending on model weights)
|
35 |
roop_model = ROOP()
|
36 |
|
37 |
+
# Step 5: Define a Gradio function to swap faces on an image and video
|
38 |
def process_face_swap(image, video):
|
39 |
+
# Use the ROOP model to perform face-swapping
|
40 |
+
print("Processing face swap...")
|
41 |
output = roop_model.swap_faces(image, video)
|
42 |
return output
|
43 |
|
44 |
+
# Step 6: Create a Gradio interface
|
45 |
+
iface = gr.Int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|