Update app.py
Browse files
app.py
CHANGED
|
@@ -6,39 +6,37 @@ 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 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
| 27 |
|
| 28 |
# Streamlit UI
|
| 29 |
st.title("Face Swapper")
|
| 30 |
-
st.
|
| 31 |
-
source_file = st.sidebar.file_uploader("Upload source image")
|
| 32 |
-
target_file = st.sidebar.file_uploader("Upload target image/video")
|
| 33 |
-
use_face_enhancer = st.sidebar.checkbox("Use only Face Enhancer", False)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
if result:
|
| 38 |
-
st.
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
if source_file:
|
| 42 |
-
os.remove(source_file.name)
|
| 43 |
-
if target_file:
|
| 44 |
-
os.remove(target_file.name)
|
|
|
|
| 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 |
+
with st.spinner("Processing..."):
|
| 10 |
+
target_extension = os.path.splitext(target)[-1]
|
| 11 |
+
output_path1 = "output1" + target_extension
|
| 12 |
+
output_path2 = "output2" + target_extension
|
| 13 |
|
| 14 |
+
if not use_face_enhancer:
|
| 15 |
+
# Run both scripts
|
| 16 |
+
cmd1 = ["python3", "run.py", "-s", source, "-t", target, "-o", output_path1, "--frame-processor", "face_swapper"]
|
| 17 |
+
subprocess.run(cmd1)
|
| 18 |
|
| 19 |
+
# Run the second script
|
| 20 |
+
cmd2 = ["python3", "run.py", "-t", target 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)
|
| 25 |
+
os.remove(target)
|
| 26 |
|
| 27 |
+
return output_path2
|
| 28 |
|
| 29 |
# Streamlit UI
|
| 30 |
st.title("Face Swapper")
|
| 31 |
+
st.write("Upload a target image/video and a source image to swap faces.")
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
source_file = st.file_uploader("Upload source image")
|
| 34 |
+
target_file = st.file_uploader("Upload target image/video")
|
| 35 |
+
use_face_enhancer = st.checkbox("Use only Face Enhancer", False)
|
| 36 |
+
|
| 37 |
+
if st.button("Swap Faces"):
|
| 38 |
+
result = run_scripts(target_file.name, source_file.name, use_face_enhancer)
|
| 39 |
if result:
|
| 40 |
+
st.image(result) # Display the result as an image
|
| 41 |
|
| 42 |
+
# No need to remove uploaded files, as they are now passed as strings.
|
|
|
|
|
|
|
|
|
|
|
|