File size: 2,296 Bytes
75f0a99 21f0a5b b3a26da 21f0a5b f5e12da b3a26da eb230df 21f0a5b f0ccc44 f5e12da eb230df 21f0a5b b3a26da eb230df f0ccc44 21f0a5b eb230df 21f0a5b eb230df b3a26da 21f0a5b eb230df 21f0a5b 4170421 89145a1 f0ccc44 eb230df f0ccc44 d7b473c eb230df 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 59 |
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, use_face_enhancer):
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 == "Face Swapper" or mode == "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 == "Face Enhancer" or mode == "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 swap")
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/video")
mode = st.radio("Choose Mode", ("Face Swapper", "Face Enhancer", "Both"))
use_face_enhancer = st.checkbox("Use Face Enhancer")
if source_file and target_file and st.button("Swap Faces"):
result = run_scripts(target_file, source_file, mode, use_face_enhancer)
if result:
st.image(result) # Display the result as an image
|