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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -14
app.py CHANGED
@@ -7,39 +7,49 @@ import gradio as gr
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
 
 
 
 
 
 
 
 
 
 
 
 
7
  repo_url = "https://github.com/lvalics/roopapi.git"
8
  repo_dir = "roopapi"
9
 
10
+ # Step 1: Clone the 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: Navigate to the 'roopapi' directory and install dependencies
 
16
  os.chdir(repo_dir)
17
 
18
+ # Install dependencies from 'requirements.txt' in the repository
19
  print("Installing dependencies from requirements.txt...")
20
  subprocess.run(["pip", "install", "-r", "requirements.txt"])
21
 
22
+ # Step 3: Add the 'roopapi' directory to Python's module search path
23
  sys.path.append(os.path.join(os.getcwd(), repo_dir))
24
 
25
+ # Step 4: Import the ROOP module (from roopapi)
26
  try:
27
+ from roop import ROOP # Importing the ROOP class from the roopapi repo
28
  print("ROOP module imported successfully.")
29
  except ModuleNotFoundError as e:
30
+ print(f"Error importing the ROOP module: {e}")
31
+ sys.exit(1) # Exit the script if ROOP is not found
32
 
33
+ # Step 5: Initialize the ROOP model
34
  roop_model = ROOP()
35
 
36
+ # Step 6: Define a Gradio interface function for face swapping
37
  def process_face_swap(image, video):
38
+ # Use the ROOP model to swap faces
39
  print("Processing face swap...")
40
  output = roop_model.swap_faces(image, video)
41
  return output
42
 
43
+ # Step 7: Create a Gradio interface for the app
44
+ iface = gr.Interface(
45
+ fn=process_face_swap,
46
+ inputs=["image", "video"], # Image and video inputs
47
+ outputs="video", # The output will be a video
48
+ live=True,
49
+ title="ROOP Face Swapping",
50
+ description="Upload an image and a video to swap faces using the ROOP model."
51
+ )
52
+
53
+ # Step 8: Launch the Gradio interface
54
+ if __name__ == "__main__":
55
+ iface.launch()