Ashrafb commited on
Commit
75f0a99
·
1 Parent(s): 38a67b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import gradio as gr
2
  import subprocess
3
  import shutil
4
  import os
@@ -6,12 +6,13 @@ import os
6
  def run_scripts(target, source, use_face_enhancer):
7
  if target is None or (not use_face_enhancer and source is None):
8
  return None
 
9
  target_extension = os.path.splitext(target.name)[-1]
10
  output_path1 = "output1" + target_extension
11
  output_path2 = "output2" + target_extension
12
 
13
  if not use_face_enhancer:
14
- # Run both scripts
15
  cmd1 = ["python3", "run.py", "-s", source.name, "-t", target.name, "-o", output_path1, "--frame-processor", "face_swapper"]
16
  subprocess.run(cmd1)
17
 
@@ -25,17 +26,19 @@ def run_scripts(target, source, use_face_enhancer):
25
 
26
  return output_path2
27
 
28
- iface = gr.Interface(
29
- fn=run_scripts,
30
- inputs=[
31
- "file",
32
- "file",
33
- gr.inputs.Checkbox(default=False, label="Use only Face Enhancer") # New checkbox input
34
- ],
35
- outputs="file",
36
- title="Face swapper",
37
- description="Upload a target image/video and a source image to swap faces.",
38
- live=True
39
- )
40
-
41
- iface.launch()
 
 
 
1
+ import streamlit as st
2
  import subprocess
3
  import shutil
4
  import os
 
6
  def run_scripts(target, source, use_face_enhancer):
7
  if target is None or (not use_face_enhancer and source is None):
8
  return None
9
+
10
  target_extension = os.path.splitext(target.name)[-1]
11
  output_path1 = "output1" + target_extension
12
  output_path2 = "output2" + target_extension
13
 
14
  if not use_face_enhancer:
15
+ # Run the first script
16
  cmd1 = ["python3", "run.py", "-s", source.name, "-t", target.name, "-o", output_path1, "--frame-processor", "face_swapper"]
17
  subprocess.run(cmd1)
18
 
 
26
 
27
  return output_path2
28
 
29
+ st.title("Face swapper")
30
+
31
+ target_image = st.file_uploader("Upload target image", type=["jpg", "png"])
32
+
33
+ source_image = st.file_uploader("Upload source image (optional)", type=["jpg", "png"])
34
+
35
+ use_face_enhancer = st.checkbox("Use only Face Enhancer", value=False)
36
+
37
+ if st.button("Swap Faces"):
38
+ output_file = run_scripts(target_image, source_image, use_face_enhancer)
39
+ if output_file:
40
+ st.success("Face swapping completed!")
41
+ st.image(output_file)
42
+ else:
43
+ st.error("Please provide a target image.")
44
+