Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ def main():
|
|
18 |
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'https://public.agent-matrix.com/publish/gradio-3.32.8-py3-none-any.whl'])
|
19 |
import gradio as gr
|
20 |
if gr.__version__ not in ['3.32.8']:
|
21 |
-
raise ModuleNotFoundError("使用项目内置Gradio获取最优体验! 请运行
|
22 |
from request_llms.bridge_all import predict
|
23 |
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, load_chat_cookies, DummyWith
|
24 |
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址
|
@@ -28,31 +28,6 @@ def main():
|
|
28 |
DARK_MODE, NUM_CUSTOM_BASIC_BTN, SSL_KEYFILE, SSL_CERTFILE = get_conf('DARK_MODE', 'NUM_CUSTOM_BASIC_BTN', 'SSL_KEYFILE', 'SSL_CERTFILE')
|
29 |
INIT_SYS_PROMPT = get_conf('INIT_SYS_PROMPT')
|
30 |
|
31 |
-
base_url_box = gr.Textbox(visible=False)
|
32 |
-
api_key_box = gr.Textbox(visible=False)
|
33 |
-
|
34 |
-
# 从 URL 获取 base_url 和 api_key 参数
|
35 |
-
def get_url_params(request: gr.Request):
|
36 |
-
base_url = request.query_params.get('base_url', '')
|
37 |
-
api_key = request.query_params.get('api_key', '')
|
38 |
-
return base_url, api_key
|
39 |
-
|
40 |
-
# 更新应用中的 base_url 和 api_key
|
41 |
-
def apply_base_url_and_api_key(cookies, base_url, api_key):
|
42 |
-
if base_url:
|
43 |
-
cookies['base_url'] = base_url
|
44 |
-
if api_key:
|
45 |
-
cookies['api_key'] = api_key
|
46 |
-
return cookies
|
47 |
-
|
48 |
-
# 更新 cookies 中的 base_url 和 api_key
|
49 |
-
def update_cookies(cookies, base_url, api_key):
|
50 |
-
if base_url:
|
51 |
-
cookies['base_url'] = base_url
|
52 |
-
if api_key:
|
53 |
-
cookies['api_key'] = api_key
|
54 |
-
return cookies
|
55 |
-
|
56 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
57 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
58 |
from check_proxy import get_current_version
|
@@ -114,7 +89,12 @@ def main():
|
|
114 |
with gr_L2(scale=1, elem_id="gpt-panel"):
|
115 |
with gr.Accordion("输入区", open=True, elem_id="input-panel") as area_input_primary:
|
116 |
with gr.Row():
|
117 |
-
txt = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
118 |
with gr.Row():
|
119 |
submitBtn = gr.Button("提交", elem_id="elem_submit", variant="primary")
|
120 |
with gr.Row():
|
@@ -404,10 +384,28 @@ def main():
|
|
404 |
outputs = [py_pickle_cookie, cookies, *customize_btns.values(), *predefined_btns.values()], _js=js_code_for_persistent_cookie_init)
|
405 |
demo.load(None, inputs=[dark_mode], outputs=None, _js="""(dark_mode)=>{apply_cookie_for_checkbox(dark_mode);}""") # 配置暗色主题或亮色主题
|
406 |
demo.load(None, inputs=[gr.Textbox(LAYOUT, visible=False)], outputs=None, _js='(LAYOUT)=>{GptAcademicJavaScriptInit(LAYOUT);}')
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
411 |
|
412 |
# gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
|
413 |
def run_delayed_tasks():
|
@@ -438,4 +436,4 @@ def main():
|
|
438 |
# blocked_paths=["config.py","config_private.py","docker-compose.yml","Dockerfile",f"{PATH_LOGGING}/admin"])
|
439 |
|
440 |
if __name__ == "__main__":
|
441 |
-
main()
|
|
|
18 |
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'https://public.agent-matrix.com/publish/gradio-3.32.8-py3-none-any.whl'])
|
19 |
import gradio as gr
|
20 |
if gr.__version__ not in ['3.32.8']:
|
21 |
+
raise ModuleNotFoundError("使用项目内置Gradio获取最优体验! 请运行 pip install -r requirements.txt 指令安装内置Gradio及其他依赖, 详情信息见requirements.txt.")
|
22 |
from request_llms.bridge_all import predict
|
23 |
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, load_chat_cookies, DummyWith
|
24 |
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址
|
|
|
28 |
DARK_MODE, NUM_CUSTOM_BASIC_BTN, SSL_KEYFILE, SSL_CERTFILE = get_conf('DARK_MODE', 'NUM_CUSTOM_BASIC_BTN', 'SSL_KEYFILE', 'SSL_CERTFILE')
|
29 |
INIT_SYS_PROMPT = get_conf('INIT_SYS_PROMPT')
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
32 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
33 |
from check_proxy import get_current_version
|
|
|
89 |
with gr_L2(scale=1, elem_id="gpt-panel"):
|
90 |
with gr.Accordion("输入区", open=True, elem_id="input-panel") as area_input_primary:
|
91 |
with gr.Row():
|
92 |
+
txt = gr.Textbox(
|
93 |
+
show_label=False,
|
94 |
+
lines=2,
|
95 |
+
placeholder="输入问题或API密钥,输入多个密钥时,用英文逗号间隔。支持多个OpenAI密钥共存。",
|
96 |
+
elem_id="user_input" # 添加 elem_id
|
97 |
+
).style(container=False)
|
98 |
with gr.Row():
|
99 |
submitBtn = gr.Button("提交", elem_id="elem_submit", variant="primary")
|
100 |
with gr.Row():
|
|
|
384 |
outputs = [py_pickle_cookie, cookies, *customize_btns.values(), *predefined_btns.values()], _js=js_code_for_persistent_cookie_init)
|
385 |
demo.load(None, inputs=[dark_mode], outputs=None, _js="""(dark_mode)=>{apply_cookie_for_checkbox(dark_mode);}""") # 配置暗色主题或亮色主题
|
386 |
demo.load(None, inputs=[gr.Textbox(LAYOUT, visible=False)], outputs=None, _js='(LAYOUT)=>{GptAcademicJavaScriptInit(LAYOUT);}')
|
387 |
+
demo.load(
|
388 |
+
None,
|
389 |
+
inputs=None,
|
390 |
+
outputs=None,
|
391 |
+
_js="""
|
392 |
+
() => {
|
393 |
+
const urlParams = new URLSearchParams(window.location.search);
|
394 |
+
const api_key = urlParams.get('api_key');
|
395 |
+
if (api_key) {
|
396 |
+
const inputBox = gradioApp().querySelector('#user_input textarea');
|
397 |
+
if (inputBox) {
|
398 |
+
inputBox.value = api_key;
|
399 |
+
inputBox.dispatchEvent(new Event('input', { bubbles: true }));
|
400 |
+
const submitBtn = gradioApp().querySelector('#elem_submit');
|
401 |
+
if (submitBtn) {
|
402 |
+
submitBtn.click();
|
403 |
+
}
|
404 |
+
}
|
405 |
+
}
|
406 |
+
}
|
407 |
+
"""
|
408 |
+
)
|
409 |
|
410 |
# gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
|
411 |
def run_delayed_tasks():
|
|
|
436 |
# blocked_paths=["config.py","config_private.py","docker-compose.yml","Dockerfile",f"{PATH_LOGGING}/admin"])
|
437 |
|
438 |
if __name__ == "__main__":
|
439 |
+
main()
|