Spaces:
Running
Running
File size: 1,599 Bytes
4d48059 3f54717 4d48059 3f54717 |
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 46 47 |
import streamlit as st
import os
import subprocess
# Function to run the provided script with user inputs
def run_script(image_path, video_path, output_quality):
script_command = (
f"python run.py --target {video_path} --output-video-quality {output_quality} "
f"--source {image_path} -o ./output/swapped.mp4 --execution-provider cuda --frame-processor face_swapper face_enhancer"
)
subprocess.run(script_command, shell=True)
# Streamlit app
def main():
st.title("Face Swapper Streamlit App")
# Upload image and video
st.header("Upload Image and Video")
image_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
video_file = st.file_uploader("Upload Video", type=["mp4"])
# Output video quality
output_quality = st.slider("Select Output Video Quality", min_value=1, max_value=100, value=80)
# Run script button
if st.button("Run Face Swapper"):
if image_file is not None and video_file is not None:
# Save uploaded files
image_path = "./input/user_image.jpg"
video_path = "./input/user_video.mp4"
image_file.save(image_path)
video_file.save(video_path)
# Create output directory
os.makedirs("./output", exist_ok=True)
# Run the script
run_script(image_path, video_path, output_quality)
# Display the output video
st.video("./output/swapped.mp4")
else:
st.warning("Please upload both an image and a video.")
if __name__ == "__main__":
main()
|