john1246 commited on
Commit
ee71b69
Β·
verified Β·
1 Parent(s): b1d1c6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -18
app.py CHANGED
@@ -1,38 +1,45 @@
1
  import os
2
  import subprocess
 
3
  import gradio as gr
4
 
5
- # Clone the GitHub repository if it's not already present
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 any necessary dependencies from requirements.txt
13
- # Change directory to the repo folder and install dependencies
14
  os.chdir(repo_dir)
 
 
 
15
  subprocess.run(["pip", "install", "-r", "requirements.txt"])
16
 
17
- # Now import the required modules from the repo
18
- from roop import ROOP
 
 
 
 
 
 
 
 
19
 
20
- # Initialize the ROOP face-swapping model
21
  roop_model = ROOP()
22
 
23
- # Define a simple Gradio function for face swapping
24
  def process_face_swap(image, video):
 
 
25
  output = roop_model.swap_faces(image, video)
26
  return output
27
 
28
- # Create the Gradio interface
29
- iface = gr.Interface(
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