Spaces:
Running
Running
File size: 1,811 Bytes
4d48059 3f54717 a75da4b 4d48059 9f1a6bb a75da4b 9f1a6bb 3f54717 a75da4b 3f54717 a75da4b 3f54717 a75da4b 3f54717 a75da4b 492235c 3f54717 a75da4b 492235c 3f54717 9f1a6bb 3f54717 a75da4b 9f1a6bb a75da4b 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 48 49 50 51 52 53 54 55 |
import streamlit as st
import os
import subprocess
from PIL import Image
from io import BytesIO
# Function to run the provided script and return the path of the generated video
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)
# Return the path of the generated video
return "/content/swapped.mp4"
# 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.read())
with open(video_path, "wb") as f:
f.write(video_file.read())
# Run the script and get the path of the generated video
generated_video_path = run_script(image_path, video_path)
# Display the swapped video
video_bytes = open(generated_video_path, "rb").read()
st.video(video_bytes)
if __name__ == "__main__":
main()
|