Spaces:
Running
Running
import streamlit as st | |
import os | |
import subprocess | |
from PIL import Image | |
from io import BytesIO | |
# Function to run the provided script | |
def run_script(image_path, video_path): | |
script = """ | |
!git clone https://github.com/s0md3v/roop.git | |
%cd roop | |
!wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O inswapper_128.onnx | |
!mkdir models | |
!mv inswapper_128.onnx ./models | |
!python run.py --target {} --output-video-quality 80 --source {} -o /content/swapped.mp4 --execution-provider cuda --frame-processor face_swapper face_enhancer | |
""".format(video_path, image_path) | |
subprocess.run(script, shell=True) | |
# Streamlit app | |
def main(): | |
st.title("Face Swapper App") | |
# File upload | |
st.sidebar.header("Upload Files") | |
image_file = st.sidebar.file_uploader("Upload Image", type=["jpg", "png", "jpeg"]) | |
video_file = st.sidebar.file_uploader("Upload Video", type=["mp4"]) | |
if st.sidebar.button("Swap Faces"): | |
if image_file is not None and video_file is not None: | |
# Save uploaded files | |
image_path = "./uploaded_image.jpg" | |
video_path = "./uploaded_video.mp4" | |
with open(image_path, "wb") as f: | |
f.write(image_file.getvalue()) | |
with open(video_path, "wb") as f: | |
f.write(video_file.getvalue()) | |
# Run the script | |
run_script(image_path, video_path) | |
# Display the swapped video | |
video_bytes = open("/content/swapped.mp4", "rb").read() | |
st.video(video_bytes) | |
if __name__ == "__main__": | |
main() | |