Ashrafb commited on
Commit
4170421
·
1 Parent(s): 2cf25c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -33
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
- def main():
34
- st.markdown('<p style="color:#191970;text-align:center;font-size:30px;">Aiconvert.online</p>', unsafe_allow_html=True)
35
- st.title("AIconvert Face swap")
36
- st.markdown('<style>h1{color: Crimson; text-align: center;}</style>', unsafe_allow_html=True)
37
-
38
- source_file = st.file_uploader("Upload Source Image", type=["jpg", "png", "jpeg"])
39
- target_file = st.file_uploader("Upload Target Image", type=["jpg", "png", "jpeg"])
40
- doFaceEnhancer = st.checkbox("Enable Face Enhancer")
41
-
42
- if source_file is not None and target_file is not None:
43
- source_image = Image.open(source_file)
44
- target_image = Image.open(target_file)
45
-
46
- st.image(source_image, caption="Source Image", use_column_width=True)
47
- st.image(target_image, caption="Target Image", use_column_width=True)
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)