Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,8 @@ import streamlit as st
|
|
| 2 |
import subprocess
|
| 3 |
import shutil
|
| 4 |
import os
|
| 5 |
-
from PIL import Image
|
| 6 |
-
import numpy as np
|
| 7 |
|
| 8 |
def run_scripts(target, source, use_face_enhancer):
|
| 9 |
-
print(f"Source: {source.name}, Target: {target.name}")
|
| 10 |
-
|
| 11 |
if target is None or (not use_face_enhancer and source is None):
|
| 12 |
return None
|
| 13 |
target_extension = os.path.splitext(target.name)[-1]
|
|
@@ -29,32 +25,20 @@ def run_scripts(target, source, use_face_enhancer):
|
|
| 29 |
|
| 30 |
return output_path2
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
if st.button("Swap Faces"):
|
| 50 |
-
with st.spinner("Swapping Faces..."):
|
| 51 |
-
output_path = run_scripts(
|
| 52 |
-
target_file,
|
| 53 |
-
source_file if not doFaceEnhancer else None,
|
| 54 |
-
doFaceEnhancer,
|
| 55 |
-
)
|
| 56 |
-
output_image = Image.open(output_path)
|
| 57 |
-
st.image(output_image, caption="Result", use_column_width=True)
|
| 58 |
-
|
| 59 |
-
if __name__ == "__main__":
|
| 60 |
-
main()
|
|
|
|
| 2 |
import subprocess
|
| 3 |
import shutil
|
| 4 |
import os
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def run_scripts(target, source, use_face_enhancer):
|
|
|
|
|
|
|
| 7 |
if target is None or (not use_face_enhancer and source is None):
|
| 8 |
return None
|
| 9 |
target_extension = os.path.splitext(target.name)[-1]
|
|
|
|
| 25 |
|
| 26 |
return output_path2
|
| 27 |
|
| 28 |
+
# Streamlit UI
|
| 29 |
+
st.title("Face Swapper")
|
| 30 |
+
st.sidebar.header("Options")
|
| 31 |
+
source_file = st.sidebar.file_uploader("Upload source image")
|
| 32 |
+
target_file = st.sidebar.file_uploader("Upload target image/video")
|
| 33 |
+
use_face_enhancer = st.sidebar.checkbox("Use only Face Enhancer", False)
|
| 34 |
+
|
| 35 |
+
if st.sidebar.button("Swap Faces"):
|
| 36 |
+
result = run_scripts(target_file, source_file, use_face_enhancer)
|
| 37 |
+
if result:
|
| 38 |
+
st.video(result) # Display the result as a video
|
| 39 |
+
|
| 40 |
+
# Cleanup uploaded files after processing
|
| 41 |
+
if source_file:
|
| 42 |
+
os.remove(source_file.name)
|
| 43 |
+
if target_file:
|
| 44 |
+
os.remove(target_file.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|