File size: 1,869 Bytes
4d48059
3f54717
 
a75da4b
 
4d48059
9f1a6bb
a75da4b
5821330
a75da4b
5821330
 
a75da4b
 
 
 
 
 
 
a6a443d
 
a75da4b
5821330
 
9f1a6bb
a6a443d
3f54717
 
 
a75da4b
3f54717
a75da4b
 
 
 
3f54717
a75da4b
3f54717
 
0cee436
 
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
56
57
58
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):
    output_video_path = "/content/roop/swapped.mp4"
    script = """
    cd /content/roop

    !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 {} --execution-provider cuda --frame-processor face_swapper face_enhancer
    """.format(video_path, image_path, output_video_path)
    
    subprocess.run(script, shell=True, cwd="/content")

    # Return the path of the generated video
    return output_video_path

# 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 = image_file
            video_path = video_file

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