File size: 1,429 Bytes
75f0a99 21f0a5b 75f0a99 21f0a5b 75f0a99 38a67b0 21f0a5b 38a67b0 21f0a5b 75f0a99 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import streamlit as st
import subprocess
import shutil
import os
def run_scripts(target, source, use_face_enhancer):
if target is None or (not use_face_enhancer and source is None):
return None
target_extension = os.path.splitext(target.name)[-1]
output_path1 = "output1" + target_extension
output_path2 = "output2" + target_extension
if not use_face_enhancer:
# Run the first script
cmd1 = ["python3", "run.py", "-s", source.name, "-t", target.name, "-o", output_path1, "--frame-processor", "face_swapper"]
subprocess.run(cmd1)
# Run the second script
cmd2 = ["python3", "run.py", "-t", target.name if use_face_enhancer else output_path1, "-o", output_path2, "--frame-processor", "face_enhancer"]
subprocess.run(cmd2)
if not use_face_enhancer:
os.remove(source.name)
os.remove(target.name)
return output_path2
st.title("Face swapper")
target_image = st.file_uploader("Upload target image", type=["jpg", "png"])
source_image = st.file_uploader("Upload source image (optional)", type=["jpg", "png"])
use_face_enhancer = st.checkbox("Use only Face Enhancer", value=False)
if st.button("Swap Faces"):
output_file = run_scripts(target_image, source_image, use_face_enhancer)
if output_file:
st.success("Face swapping completed!")
st.image(output_file)
else:
st.error("Please provide a target image.")
|