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()