Update app.py
Browse files
app.py
CHANGED
@@ -6,36 +6,50 @@ import os
|
|
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 |
-
|
10 |
target_extension = os.path.splitext(target.name)[-1]
|
11 |
output_path1 = "output1" + target_extension
|
12 |
output_path2 = "output2" + target_extension
|
13 |
|
14 |
if not use_face_enhancer:
|
|
|
15 |
cmd1 = ["python3", "run.py", "-s", source.name, "-t", target.name, "-o", output_path1, "--frame-processor", "face_swapper"]
|
16 |
subprocess.run(cmd1)
|
17 |
|
|
|
18 |
cmd2 = ["python3", "run.py", "-t", target.name if use_face_enhancer else output_path1, "-o", output_path2, "--frame-processor", "face_enhancer"]
|
19 |
subprocess.run(cmd2)
|
20 |
|
21 |
if not use_face_enhancer:
|
22 |
-
|
23 |
-
|
24 |
|
25 |
return output_path2
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
10 |
output_path1 = "output1" + target_extension
|
11 |
output_path2 = "output2" + target_extension
|
12 |
|
13 |
if not use_face_enhancer:
|
14 |
+
# Run both scripts
|
15 |
cmd1 = ["python3", "run.py", "-s", source.name, "-t", target.name, "-o", output_path1, "--frame-processor", "face_swapper"]
|
16 |
subprocess.run(cmd1)
|
17 |
|
18 |
+
# Run the second script
|
19 |
cmd2 = ["python3", "run.py", "-t", target.name if use_face_enhancer else output_path1, "-o", output_path2, "--frame-processor", "face_enhancer"]
|
20 |
subprocess.run(cmd2)
|
21 |
|
22 |
if not use_face_enhancer:
|
23 |
+
os.remove(source.name)
|
24 |
+
os.remove(target.name)
|
25 |
|
26 |
return output_path2
|
27 |
|
28 |
+
def main():
|
29 |
+
st.markdown('<p style="color:#191970;text-align:center;font-size:30px;">Aiconvert.online</p>', unsafe_allow_html=True)
|
30 |
+
st.title("AIconvert Face swap")
|
31 |
+
st.markdown('<style>h1{color: Crimson; text-align: center;}</style>', unsafe_allow_html=True)
|
32 |
+
|
33 |
+
source_file = st.file_uploader("Upload Source Image", type=["jpg", "png", "jpeg"])
|
34 |
+
target_file = st.file_uploader("Upload Target Image", type=["jpg", "png", "jpeg"])
|
35 |
+
doFaceEnhancer = st.checkbox("Enable Face Enhancer")
|
36 |
+
|
37 |
+
if source_file is not None and target_file is not None:
|
38 |
+
source_image = Image.open(source_file)
|
39 |
+
target_image = Image.open(target_file)
|
40 |
+
|
41 |
+
st.image(source_image, caption="Source Image", use_column_width=True)
|
42 |
+
st.image(target_image, caption="Target Image", use_column_width=True)
|
43 |
+
|
44 |
+
if st.button("Swap Faces"):
|
45 |
+
with st.spinner("Swapping Faces..."):
|
46 |
+
output_path = swap_face(
|
47 |
+
np.array(source_image),
|
48 |
+
np.array(target_image),
|
49 |
+
doFaceEnhancer,
|
50 |
+
)
|
51 |
+
output_image = Image.open(output_path)
|
52 |
+
st.image(output_image, caption="Result", use_column_width=True)
|
53 |
+
|
54 |
+
if __name__ == "__main__":
|
55 |
+
main()
|