Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,51 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import subprocess
|
|
|
|
|
4 |
|
5 |
-
# Function to run the provided script
|
6 |
-
def run_script(image_path, video_path
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Streamlit app
|
14 |
def main():
|
15 |
-
st.title("Face Swapper
|
16 |
-
|
17 |
-
# Upload image and video
|
18 |
-
st.header("Upload Image and Video")
|
19 |
-
image_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
20 |
-
video_file = st.file_uploader("Upload Video", type=["mp4"])
|
21 |
|
22 |
-
#
|
23 |
-
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
if st.button("Run Face Swapper"):
|
27 |
if image_file is not None and video_file is not None:
|
28 |
# Save uploaded files
|
29 |
-
image_path = "./
|
30 |
-
video_path = "./
|
31 |
-
|
32 |
-
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
|
37 |
# Run the script
|
38 |
-
run_script(image_path, video_path
|
39 |
|
40 |
-
# Display the
|
41 |
-
|
42 |
-
|
43 |
-
st.warning("Please upload both an image and a video.")
|
44 |
|
45 |
if __name__ == "__main__":
|
46 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import subprocess
|
4 |
+
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
+
# Function to run the provided script
|
8 |
+
def run_script(image_path, video_path):
|
9 |
+
script = """
|
10 |
+
!git clone https://github.com/s0md3v/roop.git
|
11 |
+
%cd roop
|
12 |
+
|
13 |
+
!wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O inswapper_128.onnx
|
14 |
+
!mkdir models
|
15 |
+
!mv inswapper_128.onnx ./models
|
16 |
+
|
17 |
+
!python run.py --target {} --output-video-quality 80 --source {} -o /content/swapped.mp4 --execution-provider cuda --frame-processor face_swapper face_enhancer
|
18 |
+
""".format(video_path, image_path)
|
19 |
+
|
20 |
+
subprocess.run(script, shell=True)
|
21 |
|
22 |
# Streamlit app
|
23 |
def main():
|
24 |
+
st.title("Face Swapper App")
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
# File upload
|
27 |
+
st.sidebar.header("Upload Files")
|
28 |
+
image_file = st.sidebar.file_uploader("Upload Image", type=["jpg", "png", "jpeg"])
|
29 |
+
video_file = st.sidebar.file_uploader("Upload Video", type=["mp4"])
|
30 |
|
31 |
+
if st.sidebar.button("Swap Faces"):
|
|
|
32 |
if image_file is not None and video_file is not None:
|
33 |
# Save uploaded files
|
34 |
+
image_path = "./uploaded_image.jpg"
|
35 |
+
video_path = "./uploaded_video.mp4"
|
36 |
+
|
37 |
+
with open(image_path, "wb") as f:
|
38 |
+
f.write(image_file.getvalue())
|
39 |
|
40 |
+
with open(video_path, "wb") as f:
|
41 |
+
f.write(video_file.getvalue())
|
42 |
|
43 |
# Run the script
|
44 |
+
run_script(image_path, video_path)
|
45 |
|
46 |
+
# Display the swapped video
|
47 |
+
video_bytes = open("/content/swapped.mp4", "rb").read()
|
48 |
+
st.video(video_bytes)
|
|
|
49 |
|
50 |
if __name__ == "__main__":
|
51 |
main()
|