Update app.py
Browse files
app.py
CHANGED
@@ -10,13 +10,12 @@ os.makedirs('temp', exist_ok=True)
|
|
10 |
|
11 |
|
12 |
|
13 |
-
def run_scripts(target, source, use_face_enhancer):
|
14 |
-
if target is None or (
|
15 |
return None
|
16 |
with st.spinner("Processing..."):
|
17 |
target_extension = os.path.splitext(target.name)[-1]
|
18 |
-
|
19 |
-
output_path2 = "output2" + target_extension
|
20 |
|
21 |
target_bytes = target.read() # Read target file as bytes
|
22 |
source_bytes = source.read() # Read source file as bytes
|
@@ -30,20 +29,18 @@ def run_scripts(target, source, use_face_enhancer):
|
|
30 |
with open(f'temp/source{target_extension}', 'wb') as f:
|
31 |
f.write(source_bytes)
|
32 |
|
33 |
-
if
|
34 |
-
|
35 |
-
cmd1 = ["python3", "run.py", "-s", f'temp/source{target_extension}', "-t", f'temp/target{target_extension}', "-o", output_path1, "--frame-processor", "face_swapper"]
|
36 |
subprocess.run(cmd1)
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
43 |
-
os.remove(f'temp/source{target_extension}')
|
44 |
os.remove(f'temp/target{target_extension}')
|
45 |
|
46 |
-
return
|
47 |
|
48 |
# Streamlit UI
|
49 |
st.markdown('<p style="color:#191970;text-align:center;font-size:30px;">Aiconvert.online</p>', unsafe_allow_html=True)
|
@@ -52,9 +49,10 @@ st.markdown('<style>h1{color: Crimson; text-align: center;}</style>', unsafe_all
|
|
52 |
|
53 |
source_file = st.file_uploader("Upload source image")
|
54 |
target_file = st.file_uploader("Upload target image/video")
|
55 |
-
|
|
|
56 |
|
57 |
if source_file and target_file and st.button("Swap Faces"):
|
58 |
-
result = run_scripts(target_file, source_file, use_face_enhancer)
|
59 |
if result:
|
60 |
-
st.image(result)
|
|
|
10 |
|
11 |
|
12 |
|
13 |
+
def run_scripts(target, source, mode, use_face_enhancer):
|
14 |
+
if target is None or (source is None):
|
15 |
return None
|
16 |
with st.spinner("Processing..."):
|
17 |
target_extension = os.path.splitext(target.name)[-1]
|
18 |
+
output_path = "output" + target_extension
|
|
|
19 |
|
20 |
target_bytes = target.read() # Read target file as bytes
|
21 |
source_bytes = source.read() # Read source file as bytes
|
|
|
29 |
with open(f'temp/source{target_extension}', 'wb') as f:
|
30 |
f.write(source_bytes)
|
31 |
|
32 |
+
if mode == "Face Swapper" or mode == "Both":
|
33 |
+
cmd1 = ["python3", "run.py", "-s", f'temp/source{target_extension}', "-t", f'temp/target{target_extension}', "-o", output_path, "--frame-processor", "face_swapper"]
|
|
|
34 |
subprocess.run(cmd1)
|
35 |
|
36 |
+
if mode == "Face Enhancer" or mode == "Both":
|
37 |
+
cmd2 = ["python3", "run.py", "-t", f'temp/target{target_extension}', "-o", output_path, "--frame-processor", "face_enhancer"]
|
38 |
+
subprocess.run(cmd2)
|
39 |
|
40 |
+
os.remove(f'temp/source{target_extension}')
|
|
|
41 |
os.remove(f'temp/target{target_extension}')
|
42 |
|
43 |
+
return output_path
|
44 |
|
45 |
# Streamlit UI
|
46 |
st.markdown('<p style="color:#191970;text-align:center;font-size:30px;">Aiconvert.online</p>', unsafe_allow_html=True)
|
|
|
49 |
|
50 |
source_file = st.file_uploader("Upload source image")
|
51 |
target_file = st.file_uploader("Upload target image/video")
|
52 |
+
mode = st.radio("Choose Mode", ("Face Swapper", "Face Enhancer", "Both"))
|
53 |
+
use_face_enhancer = st.checkbox("Use Face Enhancer")
|
54 |
|
55 |
if source_file and target_file and st.button("Swap Faces"):
|
56 |
+
result = run_scripts(target_file, source_file, mode, use_face_enhancer)
|
57 |
if result:
|
58 |
+
st.image(result) # Display the result as an image
|