tsi-org commited on
Commit
6b42bbe
·
1 Parent(s): 76d0a30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  import subprocess
3
  import shutil
4
  import os
 
 
5
 
6
  def run_scripts(target, source, use_face_enhancer):
7
  if target is None or (not use_face_enhancer and source is None):
@@ -12,20 +14,21 @@ def run_scripts(target, source, use_face_enhancer):
12
  output_path2 = "output2" + target_extension
13
 
14
  if not use_face_enhancer:
15
- # Run both scripts
16
  cmd1 = ["python3", "run.py", "-s", source.name, "-t", target.name, "-o", output_path1, "--frame-processor", "face_swapper"]
17
  subprocess.run(cmd1)
18
 
19
- # Run the second script
20
  cmd2 = ["python3", "run.py", "-t", target.name if use_face_enhancer else output_path1, "-o", output_path2, "--frame-processor", "face_enhancer"]
21
  subprocess.run(cmd2)
22
 
23
  if not use_face_enhancer:
24
  os.remove(source.name)
25
  os.remove(target.name)
26
-
27
- # Return the file path so it gets displayed in the Gradio UI
28
- return output_path2
 
 
 
29
 
30
  iface = gr.Interface(
31
  fn=run_scripts,
@@ -34,7 +37,7 @@ iface = gr.Interface(
34
  "file",
35
  gr.inputs.Checkbox(default=False, label="Use only Face Enhancer")
36
  ],
37
- outputs="file",
38
  title="Face swapper",
39
  description="Upload a target image/video and a source image to swap faces.",
40
  live=True
 
2
  import subprocess
3
  import shutil
4
  import os
5
+ from PIL import Image
6
+ import numpy as np
7
 
8
  def run_scripts(target, source, use_face_enhancer):
9
  if target is None or (not use_face_enhancer and source is None):
 
14
  output_path2 = "output2" + target_extension
15
 
16
  if not use_face_enhancer:
 
17
  cmd1 = ["python3", "run.py", "-s", source.name, "-t", target.name, "-o", output_path1, "--frame-processor", "face_swapper"]
18
  subprocess.run(cmd1)
19
 
 
20
  cmd2 = ["python3", "run.py", "-t", target.name if use_face_enhancer else output_path1, "-o", output_path2, "--frame-processor", "face_enhancer"]
21
  subprocess.run(cmd2)
22
 
23
  if not use_face_enhancer:
24
  os.remove(source.name)
25
  os.remove(target.name)
26
+
27
+ # Open the image with PIL and convert to NumPy array
28
+ with Image.open(output_path2) as img:
29
+ img_array = np.array(img)
30
+
31
+ return img_array
32
 
33
  iface = gr.Interface(
34
  fn=run_scripts,
 
37
  "file",
38
  gr.inputs.Checkbox(default=False, label="Use only Face Enhancer")
39
  ],
40
+ outputs="image", # Change the output type to image
41
  title="Face swapper",
42
  description="Upload a target image/video and a source image to swap faces.",
43
  live=True