diff --git a/func_box.py b/func_box.py index 2dcd395..89a73c4 100644 --- a/func_box.py +++ b/func_box.py @@ -4,6 +4,8 @@ # @Author : Spike # @Descr : import hashlib +import psutil +import re def md5_str(st): # 创建一个 MD5 对象 @@ -12,4 +14,27 @@ def md5_str(st): md5.update(str(st).encode()) # 获取加密后的结果 result = md5.hexdigest() - return result \ No newline at end of file + 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)) + + + diff --git a/main_private.py b/main_private.py index 59deb92..a232151 100644 --- a/main_private.py +++ b/main_private.py @@ -116,28 +116,19 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled= switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary") 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", value=initial_prompt) top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01, interactive=True, label="Top-p (nucleus sampling)", ) temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature", ) + models_box = gr.CheckboxGroup(["input加密"], + value=["input加密"], label="输入模式") checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区") - gr.Markdown(description) - with gr.Accordion("备选输入区", open=True, visible=False) as area_input_secondary: - 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") + gr.Markdown(description) # 功能区显示开关与功能区的互动 @@ -152,19 +143,16 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled= 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 - 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] predict_args = dict(fn=ArgsGeneralWrapper(predict), inputs=input_combo, outputs=output_combo) # 提交按钮、重置按钮 cancel_handles.append(txt.submit(**predict_args)) - cancel_handles.append(txt2.submit(**predict_args)) cancel_handles.append(submitBtn.click(**predict_args)) - cancel_handles.append(submitBtn2.click(**predict_args)) resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, status]) - resetBtn2.click(lambda: ([], [], "已重置"), None, [chatbot, history, status]) # 基础功能区的回调函数注册 for k in functional: 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) # 终止按钮的回调函数注册 stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles) - stopBtn2.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles) # gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数 def auto_opentab_delay(): - import threading, webbrowser, time + import threading, webbrowser, time, func_box print(f"如果浏览器没有自动打开,请复制并转到以下URL:") - print(f"\t(亮色主题): http://localhost:{PORT}") - print(f"\t(暗色主题): http://localhost:{PORT}/?__dark-theme=true") + print(f"\t(亮色主题): http://{func_box.ipaddr()}:{PORT}") + print(f"\t(暗色主题): http://{func_box.ipaddr()}:{PORT}/?__dark-theme=true") def open(): time.sleep(2) # 打开浏览器 diff --git a/toolbox.py b/toolbox.py index 7f5a766..f2d079e 100644 --- a/toolbox.py +++ b/toolbox.py @@ -6,7 +6,7 @@ import traceback import inspect import re import gradio as gr -import hashlib +import func_box from latex2mathml.converter import convert as tex2mathml 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 - if txt == "" and txt2 != "": txt_passon = txt2 + if 'input加密' in models: txt_passon = func_box.encryption_str(txt) # 引入一个有cookie的chatbot cookies.update({ 'top_p':top_p,