anurag629 commited on
Commit
a75da4b
1 Parent(s): 3f54717

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -28
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 with user inputs
6
- def run_script(image_path, video_path, output_quality):
7
- script_command = (
8
- f"python run.py --target {video_path} --output-video-quality {output_quality} "
9
- f"--source {image_path} -o ./output/swapped.mp4 --execution-provider cuda --frame-processor face_swapper face_enhancer"
10
- )
11
- subprocess.run(script_command, shell=True)
 
 
 
 
 
 
 
12
 
13
  # Streamlit app
14
  def main():
15
- st.title("Face Swapper Streamlit App")
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
- # Output video quality
23
- output_quality = st.slider("Select Output Video Quality", min_value=1, max_value=100, value=80)
 
 
24
 
25
- # Run script button
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 = "./input/user_image.jpg"
30
- video_path = "./input/user_video.mp4"
31
- image_file.save(image_path)
32
- video_file.save(video_path)
 
33
 
34
- # Create output directory
35
- os.makedirs("./output", exist_ok=True)
36
 
37
  # Run the script
38
- run_script(image_path, video_path, output_quality)
39
 
40
- # Display the output video
41
- st.video("./output/swapped.mp4")
42
- else:
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()