Spaces:
Running
Running
updated
Browse files
app.py
CHANGED
|
@@ -1,4 +1,46 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|