File size: 2,187 Bytes
75f0a99
21f0a5b
 
b3a26da
21f0a5b
 
f5e12da
 
 
 
b3a26da
 
d66018e
eb230df
21f0a5b
f0ccc44
f5e12da
eb230df
21f0a5b
b3a26da
 
 
 
 
 
 
 
 
 
 
 
a1a0f9d
d66018e
 
 
a1a0f9d
eb230df
 
21f0a5b
eb230df
b3a26da
21f0a5b
eb230df
21f0a5b
4170421
89145a1
a6078f4
89145a1
 
f0ccc44
f28c8a5
39c7e77
f0ccc44
32f813c
d66018e
4170421
eb230df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
import subprocess
import shutil
from io import BytesIO
import os


# Create 'temp' directory if it doesn't exist
os.makedirs('temp', exist_ok=True)



def run_scripts(target, source, mode):
    if target is None or (source is None):
        return None
    with st.spinner("Processing..."):
        target_extension = os.path.splitext(target.name)[-1]
        output_path = "output" + target_extension

        target_bytes = target.read()  # Read target file as bytes
        source_bytes = source.read()  # Read source file as bytes

        target_io = BytesIO(target_bytes)  # Convert bytes to BytesIO
        source_io = BytesIO(source_bytes)  # Convert bytes to BytesIO

        # Save files to temporary directory
        with open(f'temp/target{target_extension}', 'wb') as f:
            f.write(target_bytes)
        with open(f'temp/source{target_extension}', 'wb') as f:
            f.write(source_bytes)

        if mode in ["Face Swapper", "Both"]:
            cmd1 = ["python3", "run.py", "-s", f'temp/source{target_extension}', "-t", f'temp/target{target_extension}', "-o", output_path, "--frame-processor", "face_swapper"]
            subprocess.run(cmd1)

        if mode in ["Face Enhancer", "Both"]:
            cmd2 = ["python3", "run.py", "-t", f'temp/target{target_extension}', "-o", output_path, "--frame-processor", "face_enhancer"]
            subprocess.run(cmd2)

        os.remove(f'temp/source{target_extension}')
        os.remove(f'temp/target{target_extension}')

        return output_path

# Streamlit UI
st.markdown('<p style="color:#191970;text-align:center;font-size:30px;">Aiconvert.online</p>', unsafe_allow_html=True)
st.title("AIconvert Face swapper / Face Enhancer")
st.markdown('<style>h1{color: Crimson; text-align: center;}</style>', unsafe_allow_html=True)

source_file = st.file_uploader("Upload source image")
target_file = st.file_uploader("Upload target image")
mode = st.radio("Choose Mode", ("Face Swapper", "Face Enhancer"))

if source_file and target_file and st.button("Run"):
    result = run_scripts(target_file, source_file, mode)
    if result:
        st.image(result)  # Display the result as an image