aheedsajid commited on
Commit
517cbd1
1 Parent(s): 3ca1b87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -3,12 +3,12 @@ from gradio_client import Client
3
  import os
4
  import shutil
5
 
6
- # Load the APIs at the beginning
7
  client_gen_image = Client("AP123/SDXL-Lightning")
8
  client_face_swap = Client("craftgamesnetwork/face-swap")
9
 
10
  def generate_and_swap(text_input, source_image_path):
11
- # First API: Generate image from text input
12
  gen_result = client_gen_image.predict(
13
  text_input, # Text input
14
  "4-Step", # Inference steps
@@ -16,23 +16,23 @@ def generate_and_swap(text_input, source_image_path):
16
  )
17
  print("Image generated successfully.")
18
 
19
- # Move the generated image to a known location
20
  generated_image_path = "generated_image.png"
21
  shutil.move(gen_result, generated_image_path)
22
 
23
- # Second API: Face swap
24
  swap_result_path = client_face_swap.predict(
25
- generated_image_path, # Provide generated image path directly
26
- source_image_path, # Provide source image path directly
27
  api_name="/predict"
28
  )
29
  print("Faces swapped successfully.")
30
 
31
- # Read the swapped image file
32
  with open(swap_result_path, "rb") as f:
33
  swap_result_content = f.read()
34
 
35
- # Save swapped image to a file
36
  swapped_image_path = "final_image.png"
37
  with open(swapped_image_path, "wb") as f:
38
  f.write(swap_result_content)
 
3
  import os
4
  import shutil
5
 
6
+
7
  client_gen_image = Client("AP123/SDXL-Lightning")
8
  client_face_swap = Client("craftgamesnetwork/face-swap")
9
 
10
  def generate_and_swap(text_input, source_image_path):
11
+
12
  gen_result = client_gen_image.predict(
13
  text_input, # Text input
14
  "4-Step", # Inference steps
 
16
  )
17
  print("Image generated successfully.")
18
 
19
+
20
  generated_image_path = "generated_image.png"
21
  shutil.move(gen_result, generated_image_path)
22
 
23
+
24
  swap_result_path = client_face_swap.predict(
25
+ generated_image_path,
26
+ source_image_path,
27
  api_name="/predict"
28
  )
29
  print("Faces swapped successfully.")
30
 
31
+
32
  with open(swap_result_path, "rb") as f:
33
  swap_result_content = f.read()
34
 
35
+
36
  swapped_image_path = "final_image.png"
37
  with open(swapped_image_path, "wb") as f:
38
  f.write(swap_result_content)