Spaces:
Building
Building
admin
commited on
Commit
·
2000f4c
1
Parent(s):
6c94dcb
sync ms
Browse files- app.py +4 -19
- modules/cmd.py +1 -1
- modules/smtp.py +0 -66
- modules/{qr.py → splitter.py} +30 -15
- modules/trans.py +0 -69
- modules/url.py +0 -93
- utils.py +1 -25
app.py
CHANGED
@@ -3,11 +3,8 @@ from modules.data import data_converter
|
|
3 |
from modules.exif import clexif
|
4 |
from modules.gif import video2gif
|
5 |
from modules.cmd import cmd_inject
|
6 |
-
from modules.qr import qrcode
|
7 |
from modules.rct import rct_generator
|
8 |
-
from modules.
|
9 |
-
from modules.trans import translator
|
10 |
-
from modules.url import url_shortner
|
11 |
from modules.tools import webtools
|
12 |
from utils import EN_US
|
13 |
|
@@ -17,11 +14,8 @@ ZH2EN = {
|
|
17 |
"图片 EXIF 清理": "Image EXIF Cleaner",
|
18 |
"视频转 GIF 动图": "Video to GIF",
|
19 |
"命令注入测试": "CMD Injector",
|
20 |
-
"二维码生成": "QR Code",
|
21 |
"随机对照试验生成": "RCT Generator",
|
22 |
-
"
|
23 |
-
"翻译器": "Translator",
|
24 |
-
"短链接生成": "URL Shortner",
|
25 |
"在线编程辅助工具": "Web Tools",
|
26 |
}
|
27 |
|
@@ -45,20 +39,11 @@ if __name__ == "__main__":
|
|
45 |
with gr.Tab(_L("命令注入测试")):
|
46 |
cmd_inject()
|
47 |
|
48 |
-
with gr.Tab(_L("二维码生成")):
|
49 |
-
qrcode()
|
50 |
-
|
51 |
with gr.Tab(_L("随机对照试验生成")):
|
52 |
rct_generator()
|
53 |
|
54 |
-
with gr.Tab(_L("
|
55 |
-
|
56 |
-
|
57 |
-
with gr.Tab(_L("翻译器")):
|
58 |
-
translator()
|
59 |
-
|
60 |
-
with gr.Tab(_L("短链接生成")):
|
61 |
-
url_shortner()
|
62 |
|
63 |
with gr.Tab(_L("在线编程辅助工具")):
|
64 |
webtools()
|
|
|
3 |
from modules.exif import clexif
|
4 |
from modules.gif import video2gif
|
5 |
from modules.cmd import cmd_inject
|
|
|
6 |
from modules.rct import rct_generator
|
7 |
+
from modules.splitter import str_splitter
|
|
|
|
|
8 |
from modules.tools import webtools
|
9 |
from utils import EN_US
|
10 |
|
|
|
14 |
"图片 EXIF 清理": "Image EXIF Cleaner",
|
15 |
"视频转 GIF 动图": "Video to GIF",
|
16 |
"命令注入测试": "CMD Injector",
|
|
|
17 |
"随机对照试验生成": "RCT Generator",
|
18 |
+
"字符串分割": "String Splitter",
|
|
|
|
|
19 |
"在线编程辅助工具": "Web Tools",
|
20 |
}
|
21 |
|
|
|
39 |
with gr.Tab(_L("命令注入测试")):
|
40 |
cmd_inject()
|
41 |
|
|
|
|
|
|
|
42 |
with gr.Tab(_L("随机对照试验生成")):
|
43 |
rct_generator()
|
44 |
|
45 |
+
with gr.Tab(_L("字符串分割")):
|
46 |
+
str_splitter()
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
with gr.Tab(_L("在线编程辅助工具")):
|
49 |
webtools()
|
modules/cmd.py
CHANGED
@@ -3,8 +3,8 @@ import time
|
|
3 |
import threading
|
4 |
import subprocess
|
5 |
import gradio as gr
|
|
|
6 |
|
7 |
-
EN_US = os.getenv("LANG") != "zh_CN.UTF-8"
|
8 |
ZH2EN = {
|
9 |
"状态栏": "Status",
|
10 |
"执行结果": "Command output",
|
|
|
3 |
import threading
|
4 |
import subprocess
|
5 |
import gradio as gr
|
6 |
+
from utils import EN_US
|
7 |
|
|
|
8 |
ZH2EN = {
|
9 |
"状态栏": "Status",
|
10 |
"执行结果": "Command output",
|
modules/smtp.py
DELETED
@@ -1,66 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
import gradio as gr
|
3 |
-
from utils import API_SMTP, EN_US
|
4 |
-
|
5 |
-
ZH2EN = {
|
6 |
-
"收信人邮箱": "To email",
|
7 |
-
"标题": "Title",
|
8 |
-
"测试标题": "Test title",
|
9 |
-
"正文": "Content",
|
10 |
-
"SMTP 在线测试工具": "SMTP online tester",
|
11 |
-
"发信人昵称": "Sender name",
|
12 |
-
"测试昵称": "Test nickname",
|
13 |
-
"发信人邮箱": "From email",
|
14 |
-
"应用密钥": "API key",
|
15 |
-
"SMTP 服务器": "SMTP host",
|
16 |
-
"端口": "Port",
|
17 |
-
"发送状态": "Status",
|
18 |
-
}
|
19 |
-
|
20 |
-
|
21 |
-
def _L(zh_txt: str):
|
22 |
-
return ZH2EN[zh_txt] if EN_US else zh_txt
|
23 |
-
|
24 |
-
|
25 |
-
def infer(target, title, content, name, email, password, host, port):
|
26 |
-
try:
|
27 |
-
response = requests.get(
|
28 |
-
API_SMTP,
|
29 |
-
params={
|
30 |
-
"host": host,
|
31 |
-
"Port": port,
|
32 |
-
"key": password, # apikey
|
33 |
-
"email": email, # from
|
34 |
-
"mail": target, # to
|
35 |
-
"title": title, # subject
|
36 |
-
"name": name, # nickname
|
37 |
-
"text": content, # content
|
38 |
-
},
|
39 |
-
)
|
40 |
-
if response.status_code == 200:
|
41 |
-
result: dict = response.json()
|
42 |
-
return result.get("status")
|
43 |
-
|
44 |
-
else:
|
45 |
-
raise ConnectionError(f"{response.status_code}")
|
46 |
-
|
47 |
-
except Exception as e:
|
48 |
-
return f"{e}"
|
49 |
-
|
50 |
-
|
51 |
-
def smtp_tester():
|
52 |
-
return gr.Interface(
|
53 |
-
fn=infer,
|
54 |
-
inputs=[
|
55 |
-
gr.Textbox(label=_L("收信人邮箱"), placeholder="Recipient"),
|
56 |
-
gr.Textbox(label=_L("标题"), value=_L("测试标题")),
|
57 |
-
gr.TextArea(label=_L("正文"), value=_L("SMTP 在线测试工具")),
|
58 |
-
gr.Textbox(label=_L("发信人昵称"), value=_L("测试昵称")),
|
59 |
-
gr.Textbox(label=_L("发信人邮箱"), placeholder="Sender"),
|
60 |
-
gr.Textbox(label=_L("应用密钥"), placeholder="SMTP password"),
|
61 |
-
gr.Textbox(label=_L("SMTP 服务器"), value="smtp.163.com"),
|
62 |
-
gr.Slider(label=_L("端口"), minimum=0, maximum=65535, step=1, value=25),
|
63 |
-
],
|
64 |
-
outputs=gr.TextArea(label=_L("发送状态"), show_copy_button=True),
|
65 |
-
flagging_mode="never",
|
66 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/{qr.py → splitter.py}
RENAMED
@@ -1,12 +1,12 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from utils import EN_US
|
3 |
|
4 |
ZH2EN = {
|
5 |
-
"
|
6 |
-
"
|
7 |
-
"输出二维码": "QR code",
|
8 |
-
"输入文字在线生成二维码": "Enter text to generate a QR code.",
|
9 |
"状态栏": "Status",
|
|
|
10 |
}
|
11 |
|
12 |
|
@@ -14,31 +14,46 @@ def _L(zh_txt: str):
|
|
14 |
return ZH2EN[zh_txt] if EN_US else zh_txt
|
15 |
|
16 |
|
17 |
-
def infer(
|
18 |
status = "Success"
|
19 |
-
|
20 |
try:
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
except Exception as e:
|
27 |
status = f"{e}"
|
28 |
|
29 |
-
return status,
|
30 |
|
31 |
|
32 |
-
def
|
33 |
return gr.Interface(
|
34 |
fn=infer,
|
35 |
inputs=[
|
36 |
-
gr.
|
37 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
],
|
39 |
outputs=[
|
40 |
gr.Textbox(label=_L("状态栏"), show_copy_button=True),
|
41 |
-
gr.
|
42 |
],
|
43 |
flagging_mode="never",
|
44 |
)
|
|
|
1 |
+
import math
|
2 |
import gradio as gr
|
3 |
from utils import EN_US
|
4 |
|
5 |
ZH2EN = {
|
6 |
+
"待分割字符串": "String to be split",
|
7 |
+
"分割步长": "Split step",
|
|
|
|
|
8 |
"状态栏": "Status",
|
9 |
+
"分割结果": "Split result",
|
10 |
}
|
11 |
|
12 |
|
|
|
14 |
return ZH2EN[zh_txt] if EN_US else zh_txt
|
15 |
|
16 |
|
17 |
+
def infer(cookie: str, step: int):
|
18 |
status = "Success"
|
19 |
+
output = ""
|
20 |
try:
|
21 |
+
cookie = cookie.strip()
|
22 |
+
if not cookie:
|
23 |
+
raise ValueError("请输入 cookie !")
|
24 |
+
|
25 |
+
size = len(cookie)
|
26 |
+
count = math.ceil(size / step)
|
27 |
+
for i in range(count):
|
28 |
+
output += f"""
|
29 |
+
## {i + 1}
|
30 |
+
```txt
|
31 |
+
{cookie[i * step : min((i + 1) * step, size)]}
|
32 |
+
```
|
33 |
+
"""
|
34 |
|
35 |
except Exception as e:
|
36 |
status = f"{e}"
|
37 |
|
38 |
+
return status, output
|
39 |
|
40 |
|
41 |
+
def str_splitter():
|
42 |
return gr.Interface(
|
43 |
fn=infer,
|
44 |
inputs=[
|
45 |
+
gr.TextArea(label=_L("待分割字符串")),
|
46 |
+
gr.Slider(
|
47 |
+
label=_L("分割步长"),
|
48 |
+
minimum=1,
|
49 |
+
maximum=255959,
|
50 |
+
step=1,
|
51 |
+
value=1024,
|
52 |
+
),
|
53 |
],
|
54 |
outputs=[
|
55 |
gr.Textbox(label=_L("状态栏"), show_copy_button=True),
|
56 |
+
gr.Markdown(label=_L("分割结果"), container=True, show_copy_button=True),
|
57 |
],
|
58 |
flagging_mode="never",
|
59 |
)
|
modules/trans.py
DELETED
@@ -1,69 +0,0 @@
|
|
1 |
-
import json
|
2 |
-
import requests
|
3 |
-
import gradio as gr
|
4 |
-
from utils import API_TRANS, KEY_TRANS, EN_US
|
5 |
-
|
6 |
-
ZH2EN = {
|
7 |
-
"输入文本区域": "Input text area",
|
8 |
-
"在这里输入文本...": "Type the text here...",
|
9 |
-
"模式": "Mode",
|
10 |
-
"翻译结果": "Translation results",
|
11 |
-
"状态栏": "Status",
|
12 |
-
}
|
13 |
-
|
14 |
-
|
15 |
-
def _L(zh_txt: str):
|
16 |
-
return ZH2EN[zh_txt] if EN_US else zh_txt
|
17 |
-
|
18 |
-
|
19 |
-
def infer(source, direction):
|
20 |
-
status = "Success"
|
21 |
-
result = None
|
22 |
-
payload = {
|
23 |
-
"source": source,
|
24 |
-
"trans_type": direction,
|
25 |
-
"request_id": "demo",
|
26 |
-
"detect": True,
|
27 |
-
}
|
28 |
-
headers = {
|
29 |
-
"content-type": "application/json",
|
30 |
-
"x-authorization": f"token {KEY_TRANS}",
|
31 |
-
}
|
32 |
-
try:
|
33 |
-
if not source or not direction:
|
34 |
-
raise ValueError("请输入有效文本并选择模式!")
|
35 |
-
|
36 |
-
response = requests.request(
|
37 |
-
"POST",
|
38 |
-
API_TRANS,
|
39 |
-
data=json.dumps(payload),
|
40 |
-
headers=headers,
|
41 |
-
)
|
42 |
-
|
43 |
-
result = json.loads(response.text)["target"]
|
44 |
-
|
45 |
-
except Exception as e:
|
46 |
-
status = f"{e}"
|
47 |
-
|
48 |
-
return status, result
|
49 |
-
|
50 |
-
|
51 |
-
def translator():
|
52 |
-
return gr.Interface(
|
53 |
-
fn=infer,
|
54 |
-
inputs=[
|
55 |
-
gr.TextArea(label=_L("输入文本区域"), placeholder=_L("在这里输入文本...")),
|
56 |
-
gr.Textbox(label=_L("模式"), value="auto2en"),
|
57 |
-
],
|
58 |
-
outputs=[
|
59 |
-
gr.Textbox(label=_L("状态栏"), show_copy_button=True),
|
60 |
-
gr.TextArea(label=_L("翻译结果"), show_copy_button=True),
|
61 |
-
],
|
62 |
-
flagging_mode="never",
|
63 |
-
examples=[
|
64 |
-
["彩云小译是最好的翻译服务。", "auto2ja"],
|
65 |
-
["彩云小译は最高の翻訳サービスです", "auto2en"],
|
66 |
-
["Lingocloud is the best translation service.", "auto2zh"],
|
67 |
-
],
|
68 |
-
cache_examples=False,
|
69 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/url.py
DELETED
@@ -1,93 +0,0 @@
|
|
1 |
-
import json
|
2 |
-
import requests
|
3 |
-
import gradio as gr
|
4 |
-
from utils import is_valid_url, HEADER, EN_US
|
5 |
-
|
6 |
-
ZH2EN = {
|
7 |
-
"输入长链接": "Input a long URL",
|
8 |
-
"选择 API 提供商": "Select an API provider",
|
9 |
-
"输出短链接": "Output short URL",
|
10 |
-
"预览短链接": "Preview short URL",
|
11 |
-
"将长链接转换为短的、易于共享的链接": "Convert long urls into short, easy-to-share links",
|
12 |
-
"状态栏": "Status",
|
13 |
-
}
|
14 |
-
|
15 |
-
|
16 |
-
def _L(zh_txt: str):
|
17 |
-
return ZH2EN[zh_txt] if EN_US else zh_txt
|
18 |
-
|
19 |
-
|
20 |
-
def noxlink(longUrl: str, domain="https://noxlink.net"):
|
21 |
-
api = f"{domain}/zh-CN/shorten"
|
22 |
-
response = requests.post(api, json={"longUrl": longUrl}, headers=HEADER)
|
23 |
-
if response.status_code == 200:
|
24 |
-
retcode = json.loads(response.text)
|
25 |
-
if retcode["success"]:
|
26 |
-
return f"{domain}/" + retcode["message"]
|
27 |
-
|
28 |
-
raise ConnectionError(response.text)
|
29 |
-
|
30 |
-
|
31 |
-
def monojson(longUrl: str):
|
32 |
-
response = requests.post(
|
33 |
-
"https://monojson.com/api/short-link",
|
34 |
-
json={"url": longUrl},
|
35 |
-
headers=HEADER,
|
36 |
-
)
|
37 |
-
if response.status_code == 200:
|
38 |
-
return json.loads(response.text)["shortUrl"]
|
39 |
-
else:
|
40 |
-
raise ConnectionError(response.text)
|
41 |
-
|
42 |
-
|
43 |
-
# outer func
|
44 |
-
def infer(longUrl: str, tool: str):
|
45 |
-
status = "Success"
|
46 |
-
shortUrl = preview = None
|
47 |
-
try:
|
48 |
-
if tool == "monojson":
|
49 |
-
shortUrl = monojson(longUrl)
|
50 |
-
elif tool == "noxlink":
|
51 |
-
shortUrl = noxlink(longUrl)
|
52 |
-
else:
|
53 |
-
raise ValueError("请选择一个 API 提供商!")
|
54 |
-
|
55 |
-
if is_valid_url(shortUrl):
|
56 |
-
preview = f'<a href="{shortUrl}" target="_blank">{shortUrl}</a>'
|
57 |
-
|
58 |
-
except Exception as e:
|
59 |
-
status = f"{e}"
|
60 |
-
|
61 |
-
return status, shortUrl, preview
|
62 |
-
|
63 |
-
|
64 |
-
def url_shortner():
|
65 |
-
return gr.Interface(
|
66 |
-
fn=infer,
|
67 |
-
inputs=[
|
68 |
-
gr.Textbox(
|
69 |
-
label=_L("输入长链接"),
|
70 |
-
placeholder=_L("将长链接转换为短的、易于共享的链接"),
|
71 |
-
),
|
72 |
-
gr.Dropdown(
|
73 |
-
choices=["noxlink", "monojson"],
|
74 |
-
label=_L("选择 API 提供商"),
|
75 |
-
value="noxlink",
|
76 |
-
),
|
77 |
-
],
|
78 |
-
outputs=[
|
79 |
-
gr.Textbox(label=_L("状态栏"), show_copy_button=True),
|
80 |
-
gr.Textbox(label=_L("输出短链接"), show_copy_button=True),
|
81 |
-
gr.HTML(
|
82 |
-
container=True,
|
83 |
-
show_label=True,
|
84 |
-
label=_L("预览短链接"),
|
85 |
-
),
|
86 |
-
],
|
87 |
-
flagging_mode="never",
|
88 |
-
examples=[
|
89 |
-
["https://www.bing.com", "noxlink"],
|
90 |
-
["https://www.baidu.com", "monojson"],
|
91 |
-
],
|
92 |
-
cache_examples=False,
|
93 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils.py
CHANGED
@@ -1,17 +1,8 @@
|
|
1 |
import os
|
2 |
-
import re
|
3 |
import shutil
|
4 |
import zipfile
|
5 |
|
6 |
EN_US = os.getenv("LANG") != "zh_CN.UTF-8"
|
7 |
-
API_SMTP = os.getenv("api_smtp")
|
8 |
-
API_TRANS = os.getenv("api_caiyun")
|
9 |
-
KEY_TRANS = os.getenv("apikey_caiyun")
|
10 |
-
if not (API_SMTP and API_TRANS and KEY_TRANS):
|
11 |
-
print("请检查环境变量")
|
12 |
-
exit()
|
13 |
-
|
14 |
-
|
15 |
TMP_DIR = "./__pycache__"
|
16 |
HEADER = {
|
17 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0",
|
@@ -23,13 +14,10 @@ def mk_dir(dir_path: str):
|
|
23 |
os.makedirs(dir_path)
|
24 |
|
25 |
|
26 |
-
def
|
27 |
if os.path.exists(dir_path):
|
28 |
shutil.rmtree(dir_path)
|
29 |
|
30 |
-
|
31 |
-
def clean_dir(dir_path: str):
|
32 |
-
rm_dir(dir_path)
|
33 |
os.makedirs(dir_path)
|
34 |
|
35 |
|
@@ -57,15 +45,3 @@ def compress(folder_path: str, zip_file: str):
|
|
57 |
file_path,
|
58 |
arcname=os.path.join(os.path.basename(folder_path), relative_path),
|
59 |
)
|
60 |
-
|
61 |
-
|
62 |
-
def is_valid_url(url):
|
63 |
-
# 定义 URL 的正则表达式
|
64 |
-
pattern = re.compile(
|
65 |
-
r"^(https?://)?" # 协议(http 或 https,可选)
|
66 |
-
r"([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}" # 域名
|
67 |
-
r"(:\d+)?" # 端口号(可选)
|
68 |
-
r"(/[^ ]*)?$" # 路径(可选)
|
69 |
-
)
|
70 |
-
# 使用正则表达式匹配 URL
|
71 |
-
return bool(pattern.match(url))
|
|
|
1 |
import os
|
|
|
2 |
import shutil
|
3 |
import zipfile
|
4 |
|
5 |
EN_US = os.getenv("LANG") != "zh_CN.UTF-8"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
TMP_DIR = "./__pycache__"
|
7 |
HEADER = {
|
8 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0",
|
|
|
14 |
os.makedirs(dir_path)
|
15 |
|
16 |
|
17 |
+
def clean_dir(dir_path: str):
|
18 |
if os.path.exists(dir_path):
|
19 |
shutil.rmtree(dir_path)
|
20 |
|
|
|
|
|
|
|
21 |
os.makedirs(dir_path)
|
22 |
|
23 |
|
|
|
45 |
file_path,
|
46 |
arcname=os.path.join(os.path.basename(folder_path), relative_path),
|
47 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|