deepfake / app.py
anurag629's picture
Update app.py
9f1a6bb
raw
history blame
No virus
1.81 kB
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()