增加关键字加密功能
This commit is contained in:
27
func_box.py
27
func_box.py
@ -4,6 +4,8 @@
|
|||||||
# @Author : Spike
|
# @Author : Spike
|
||||||
# @Descr :
|
# @Descr :
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import psutil
|
||||||
|
import re
|
||||||
|
|
||||||
def md5_str(st):
|
def md5_str(st):
|
||||||
# 创建一个 MD5 对象
|
# 创建一个 MD5 对象
|
||||||
@ -12,4 +14,27 @@ def md5_str(st):
|
|||||||
md5.update(str(st).encode())
|
md5.update(str(st).encode())
|
||||||
# 获取加密后的结果
|
# 获取加密后的结果
|
||||||
result = md5.hexdigest()
|
result = md5.hexdigest()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def ipaddr(): # 获取本地ipx
|
||||||
|
ip = psutil.net_if_addrs()
|
||||||
|
for i in ip:
|
||||||
|
if ip[i][0][3]:
|
||||||
|
return ip[i][0][1]
|
||||||
|
|
||||||
|
def encryption_str(txt: str):
|
||||||
|
"""(关键字)(加密间隔)匹配机制(关键字间隔)"""
|
||||||
|
pattern = re.compile(rf"(Authorization|WPS-Sid|Cookie)(:|\s+)\s*(\S+)[\s\S]*?(?=\n|$|\s)", re.IGNORECASE)
|
||||||
|
result = pattern.sub(lambda x: x.group(1) + ": XXXXXXXX", txt)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
txt = "Authorization: WPS-2:AqY7ik9XQ92tvO7+NlCRvA==:b2f626f496de9c256605a15985c855a8b3e4be99\nwps-Sid: V02SgISzdeWrYdwvW_xbib-fGlqUIIw00afc5b890008c1976f\nCookie: wpsua=V1BTVUEvMS4wIChhbmRyb2lkLW9mZmljZToxNy41O2FuZHJvaWQ6MTA7ZjIwZDAyNWQzYTM5MmExMDBiYzgxNWI2NmI3Y2E5ODI6ZG1sMmJ5QldNakF5TUVFPSl2aXZvL1YyMDIwQQ=="
|
||||||
|
txt = "Authorization: WPS-2:AqY7ik9XQ92tvO7+NlCRvA==:b2f626f496de9c256605a15985c855a8b3e4be99"
|
||||||
|
print(encryption_str(txt))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -116,28 +116,19 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled=
|
|||||||
switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary")
|
switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary")
|
||||||
|
|
||||||
with gr.Tab('Setting'):
|
with gr.Tab('Setting'):
|
||||||
with gr.Accordion("展开SysPrompt & 交互界面布局 & Github地址", open=(LAYOUT == "TOP-DOWN")):
|
with gr.Accordion("展开SysPrompt & 交互界面布局 & Github地址", open=True):
|
||||||
system_prompt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt",
|
system_prompt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt",
|
||||||
value=initial_prompt)
|
value=initial_prompt)
|
||||||
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01, interactive=True,
|
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01, interactive=True,
|
||||||
label="Top-p (nucleus sampling)", )
|
label="Top-p (nucleus sampling)", )
|
||||||
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True,
|
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True,
|
||||||
label="Temperature", )
|
label="Temperature", )
|
||||||
|
models_box = gr.CheckboxGroup(["input加密"],
|
||||||
|
value=["input加密"], label="输入模式")
|
||||||
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区"],
|
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区"],
|
||||||
value=["基础功能区", "函数插件区"], label="显示/隐藏功能区")
|
value=["基础功能区", "函数插件区"], label="显示/隐藏功能区")
|
||||||
gr.Markdown(description)
|
|
||||||
|
|
||||||
with gr.Accordion("备选输入区", open=True, visible=False) as area_input_secondary:
|
gr.Markdown(description)
|
||||||
with gr.Row():
|
|
||||||
txt2 = gr.Textbox(show_label=False, placeholder="Input question here.", label="输入区2").style(
|
|
||||||
container=False)
|
|
||||||
with gr.Row():
|
|
||||||
submitBtn2 = gr.Button("提交", variant="primary")
|
|
||||||
with gr.Row():
|
|
||||||
resetBtn2 = gr.Button("重置", variant="secondary");
|
|
||||||
resetBtn.style(size="sm")
|
|
||||||
stopBtn2 = gr.Button("停止", variant="secondary");
|
|
||||||
stopBtn.style(size="sm")
|
|
||||||
|
|
||||||
|
|
||||||
# 功能区显示开关与功能区的互动
|
# 功能区显示开关与功能区的互动
|
||||||
@ -152,19 +143,16 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled=
|
|||||||
|
|
||||||
|
|
||||||
checkboxes.select(fn_area_visibility, [checkboxes],
|
checkboxes.select(fn_area_visibility, [checkboxes],
|
||||||
[area_basic_fn, area_crazy_fn, area_input_primary, txt, txt2])
|
[area_basic_fn, area_crazy_fn, area_input_primary, txt])
|
||||||
# 整理反复出现的控件句柄组合
|
# 整理反复出现的控件句柄组合
|
||||||
# submitBtn.info
|
# submitBtn.info
|
||||||
input_combo = [cookies, txt, txt2, top_p, temperature, chatbot, history, system_prompt]
|
input_combo = [cookies, txt, top_p, temperature, chatbot, history, system_prompt, models_box]
|
||||||
output_combo = [cookies, chatbot, history, status]
|
output_combo = [cookies, chatbot, history, status]
|
||||||
predict_args = dict(fn=ArgsGeneralWrapper(predict), inputs=input_combo, outputs=output_combo)
|
predict_args = dict(fn=ArgsGeneralWrapper(predict), inputs=input_combo, outputs=output_combo)
|
||||||
# 提交按钮、重置按钮
|
# 提交按钮、重置按钮
|
||||||
cancel_handles.append(txt.submit(**predict_args))
|
cancel_handles.append(txt.submit(**predict_args))
|
||||||
cancel_handles.append(txt2.submit(**predict_args))
|
|
||||||
cancel_handles.append(submitBtn.click(**predict_args))
|
cancel_handles.append(submitBtn.click(**predict_args))
|
||||||
cancel_handles.append(submitBtn2.click(**predict_args))
|
|
||||||
resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, status])
|
resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, status])
|
||||||
resetBtn2.click(lambda: ([], [], "已重置"), None, [chatbot, history, status])
|
|
||||||
# 基础功能区的回调函数注册
|
# 基础功能区的回调函数注册
|
||||||
for k in functional:
|
for k in functional:
|
||||||
click_handle = functional[k]["Button"].click(fn=ArgsGeneralWrapper(predict),
|
click_handle = functional[k]["Button"].click(fn=ArgsGeneralWrapper(predict),
|
||||||
@ -205,15 +193,14 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled=
|
|||||||
cancel_handles.append(click_handle)
|
cancel_handles.append(click_handle)
|
||||||
# 终止按钮的回调函数注册
|
# 终止按钮的回调函数注册
|
||||||
stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles)
|
stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles)
|
||||||
stopBtn2.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles)
|
|
||||||
|
|
||||||
|
|
||||||
# gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
|
# gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
|
||||||
def auto_opentab_delay():
|
def auto_opentab_delay():
|
||||||
import threading, webbrowser, time
|
import threading, webbrowser, time, func_box
|
||||||
print(f"如果浏览器没有自动打开,请复制并转到以下URL:")
|
print(f"如果浏览器没有自动打开,请复制并转到以下URL:")
|
||||||
print(f"\t(亮色主题): http://localhost:{PORT}")
|
print(f"\t(亮色主题): http://{func_box.ipaddr()}:{PORT}")
|
||||||
print(f"\t(暗色主题): http://localhost:{PORT}/?__dark-theme=true")
|
print(f"\t(暗色主题): http://{func_box.ipaddr()}:{PORT}/?__dark-theme=true")
|
||||||
|
|
||||||
def open():
|
def open():
|
||||||
time.sleep(2) # 打开浏览器
|
time.sleep(2) # 打开浏览器
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import traceback
|
|||||||
import inspect
|
import inspect
|
||||||
import re
|
import re
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
import hashlib
|
import func_box
|
||||||
from latex2mathml.converter import convert as tex2mathml
|
from latex2mathml.converter import convert as tex2mathml
|
||||||
from functools import wraps, lru_cache
|
from functools import wraps, lru_cache
|
||||||
|
|
||||||
@ -29,9 +29,9 @@ def ArgsGeneralWrapper(f):
|
|||||||
"""
|
"""
|
||||||
装饰器函数,用于重组输入参数,改变输入参数的顺序与结构。
|
装饰器函数,用于重组输入参数,改变输入参数的顺序与结构。
|
||||||
"""
|
"""
|
||||||
def decorated(cookies, txt, txt2, top_p, temperature, chatbot, history, system_prompt, request: gr.Request, *args):
|
def decorated(cookies, txt, top_p, temperature, chatbot, history, system_prompt, models, request: gr.Request, *args):
|
||||||
txt_passon = txt
|
txt_passon = txt
|
||||||
if txt == "" and txt2 != "": txt_passon = txt2
|
if 'input加密' in models: txt_passon = func_box.encryption_str(txt)
|
||||||
# 引入一个有cookie的chatbot
|
# 引入一个有cookie的chatbot
|
||||||
cookies.update({
|
cookies.update({
|
||||||
'top_p':top_p,
|
'top_p':top_p,
|
||||||
|
|||||||
Reference in New Issue
Block a user