Compare commits
6 Commits
version3.5
...
version3.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
491174095a | ||
|
|
49cea97822 | ||
|
|
6310b65d70 | ||
|
|
93c76e1809 | ||
|
|
f64cf7a3d1 | ||
|
|
fdffbee1b0 |
12
config.py
12
config.py
@@ -48,6 +48,7 @@ DEFAULT_WORKER_NUM = 3
|
||||
THEME = "Default"
|
||||
AVAIL_THEMES = ["Default", "Chuanhu-Small-and-Beautiful", "High-Contrast", "Gstaff/Xkcd", "NoCrypt/Miku"]
|
||||
|
||||
|
||||
# 对话窗的高度 (仅在LAYOUT="TOP-DOWN"时生效)
|
||||
CHATBOT_HEIGHT = 1115
|
||||
|
||||
@@ -58,7 +59,10 @@ CODE_HIGHLIGHT = True
|
||||
|
||||
# 窗口布局
|
||||
LAYOUT = "LEFT-RIGHT" # "LEFT-RIGHT"(左右布局) # "TOP-DOWN"(上下布局)
|
||||
DARK_MODE = True # 暗色模式 / 亮色模式
|
||||
|
||||
|
||||
# 暗色模式 / 亮色模式
|
||||
DARK_MODE = True
|
||||
|
||||
|
||||
# 发送请求到OpenAI后,等待多久判定为超时
|
||||
@@ -179,10 +183,16 @@ GROBID_URLS = [
|
||||
|
||||
# 是否允许通过自然语言描述修改本页的配置,该功能具有一定的危险性,默认关闭
|
||||
ALLOW_RESET_CONFIG = False
|
||||
|
||||
|
||||
# 临时的上传文件夹位置,请勿修改
|
||||
PATH_PRIVATE_UPLOAD = "private_upload"
|
||||
|
||||
|
||||
# 日志文件夹的位置,请勿修改
|
||||
PATH_LOGGING = "gpt_log"
|
||||
|
||||
|
||||
# 除了连接OpenAI之外,还有哪些场合允许使用代理,请勿修改
|
||||
WHEN_TO_USE_PROXY = ["Download_LLM", "Download_Gradio_Theme", "Connect_Grobid", "Warmup_Modules"]
|
||||
|
||||
|
||||
@@ -1,4 +1,28 @@
|
||||
#【请修改完参数后,删除此行】请在以下方案中选择一种,然后删除其他的方案,最后docker-compose up运行 | Please choose from one of these options below, delete other options as well as This Line
|
||||
## ===================================================
|
||||
# docker-compose.yml
|
||||
## ===================================================
|
||||
# 1. 请在以下方案中选择任意一种,然后删除其他的方案
|
||||
# 2. 修改你选择的方案中的environment环境变量,详情请见github wiki或者config.py
|
||||
# 3. 选择一种暴露服务端口的方法,并对相应的配置做出修改:
|
||||
# 【方法1: 适用于Linux,很方便,可惜windows不支持】与宿主的网络融合为一体,这个是默认配置
|
||||
# network_mode: "host"
|
||||
# 【方法2: 适用于所有系统包括Windows和MacOS】端口映射,把容器的端口映射到宿主的端口(注意您需要先删除network_mode: "host",再追加以下内容)
|
||||
# ports:
|
||||
# - "12345:12345" # 注意!12345必须与WEB_PORT环境变量相互对应
|
||||
# 4. 最后`docker-compose up`运行
|
||||
# 5. 如果希望使用显卡,请关注 LOCAL_MODEL_DEVICE 和 英伟达显卡运行时 选项
|
||||
## ===================================================
|
||||
# 1. Please choose one of the following options and delete the others.
|
||||
# 2. Modify the environment variables in the selected option, see GitHub wiki or config.py for more details.
|
||||
# 3. Choose a method to expose the server port and make the corresponding configuration changes:
|
||||
# [Method 1: Suitable for Linux, convenient, but not supported for Windows] Fusion with the host network, this is the default configuration
|
||||
# network_mode: "host"
|
||||
# [Method 2: Suitable for all systems including Windows and MacOS] Port mapping, mapping the container port to the host port (note that you need to delete network_mode: "host" first, and then add the following content)
|
||||
# ports:
|
||||
# - "12345: 12345" # Note! 12345 must correspond to the WEB_PORT environment variable.
|
||||
# 4. Finally, run `docker-compose up`.
|
||||
# 5. If you want to use a graphics card, pay attention to the LOCAL_MODEL_DEVICE and Nvidia GPU runtime options.
|
||||
## ===================================================
|
||||
|
||||
## ===================================================
|
||||
## 【方案零】 部署项目的全部能力(这个是包含cuda和latex的大型镜像。如果您网速慢、硬盘小或没有显卡,则不推荐使用这个)
|
||||
@@ -39,10 +63,14 @@ services:
|
||||
# count: 1
|
||||
# capabilities: [gpu]
|
||||
|
||||
# 与宿主的网络融合
|
||||
# 【WEB_PORT暴露方法1: 适用于Linux】与宿主的网络融合
|
||||
network_mode: "host"
|
||||
|
||||
# 不使用代理网络拉取最新代码
|
||||
# 【WEB_PORT暴露方法2: 适用于所有系统】端口映射
|
||||
# ports:
|
||||
# - "12345:12345" # 12345必须与WEB_PORT相互对应
|
||||
|
||||
# 启动容器后,运行main.py主程序
|
||||
command: >
|
||||
bash -c "python3 -u main.py"
|
||||
|
||||
|
||||
Binary file not shown.
@@ -322,7 +322,7 @@
|
||||
"任何文件": "Any file",
|
||||
"但推荐上传压缩文件": "But it is recommended to upload compressed files",
|
||||
"更换模型 & SysPrompt & 交互界面布局": "Change model & SysPrompt & interactive interface layout",
|
||||
"底部输入区": "Bottom input area",
|
||||
"浮动输入区": "Floating input area",
|
||||
"输入清除键": "Input clear key",
|
||||
"插件参数区": "Plugin parameter area",
|
||||
"显示/隐藏功能区": "Show/hide function area",
|
||||
@@ -2513,5 +2513,141 @@
|
||||
"此处待注入的知识库名称id": "The knowledge base name ID to be injected here",
|
||||
"您需要构建知识库后再运行此插件": "You need to build the knowledge base before running this plugin",
|
||||
"判定是否为公式 | 测试1 写出洛伦兹定律": "Determine whether it is a formula | Test 1 write out the Lorentz law",
|
||||
"构建知识库后": "After building the knowledge base"
|
||||
"构建知识库后": "After building the knowledge base",
|
||||
"找不到本地项目或无法处理": "Unable to find local project or unable to process",
|
||||
"再做一个小修改": "Make another small modification",
|
||||
"解析整个Matlab项目": "Parse the entire Matlab project",
|
||||
"需要用GPT提取参数": "Need to extract parameters using GPT",
|
||||
"文件路径": "File path",
|
||||
"正在排队": "In queue",
|
||||
"-=-=-=-=-=-=-=-= 写出第1个文件": "-=-=-=-=-=-=-=-= Write the first file",
|
||||
"仅翻译后的文本 -=-=-=-=-=-=-=-=": "Translated text only -=-=-=-=-=-=-=-=",
|
||||
"对话通道": "Conversation channel",
|
||||
"找不到任何": "Unable to find any",
|
||||
"正在启动": "Starting",
|
||||
"开始创建新进程并执行代码! 时间限制": "Start creating a new process and executing the code! Time limit",
|
||||
"解析Matlab项目": "Parse Matlab project",
|
||||
"更换UI主题": "Change UI theme",
|
||||
"⭐ 开始啦 !": "⭐ Let's start!",
|
||||
"先提取当前英文标题": "First extract the current English title",
|
||||
"睡一会防止触发google反爬虫": "Sleep for a while to prevent triggering Google anti-crawler",
|
||||
"测试": "Test",
|
||||
"-=-=-=-=-=-=-=-= 写出Markdown文件 -=-=-=-=-=-=-=-=": "-=-=-=-=-=-=-=-= Write out Markdown file",
|
||||
"如果index是1的话": "If the index is 1",
|
||||
"VoidTerminal已经实现了类似的代码": "VoidTerminal has already implemented similar code",
|
||||
"等待线程锁": "Waiting for thread lock",
|
||||
"那么我们默认代理生效": "Then we default to proxy",
|
||||
"结果是一个有效文件": "The result is a valid file",
|
||||
"⭐ 检查模块": "⭐ Check module",
|
||||
"备份一份History作为记录": "Backup a copy of History as a record",
|
||||
"作者Binary-Husky": "Author Binary-Husky",
|
||||
"将csv文件转excel表格": "Convert CSV file to Excel table",
|
||||
"获取文章摘要": "Get article summary",
|
||||
"次代码生成尝试": "Attempt to generate code",
|
||||
"如果参数是空的": "If the parameter is empty",
|
||||
"请配置讯飞星火大模型的XFYUN_APPID": "Please configure XFYUN_APPID for the Xunfei Starfire model",
|
||||
"-=-=-=-=-=-=-=-= 写出第2个文件": "Write the second file",
|
||||
"代码生成阶段结束": "Code generation phase completed",
|
||||
"则进行提醒": "Then remind",
|
||||
"处理异常": "Handle exception",
|
||||
"可能触发了google反爬虫机制": "May have triggered Google anti-crawler mechanism",
|
||||
"AnalyzeAMatlabProject的所有源文件": "All source files of AnalyzeAMatlabProject",
|
||||
"写入": "Write",
|
||||
"我们5秒后再试一次...": "Let's try again in 5 seconds...",
|
||||
"判断一下用户是否错误地通过对话通道进入": "Check if the user entered through the dialogue channel by mistake",
|
||||
"结果": "Result",
|
||||
"2. 如果没有文件": "2. If there is no file",
|
||||
"由 test_on_sentence_end": "By test_on_sentence_end",
|
||||
"则直接使用first section name": "Then directly use the first section name",
|
||||
"太懒了": "Too lazy",
|
||||
"记录当前的大章节标题": "Record the current chapter title",
|
||||
"然后再次点击该插件! 至于您的文件": "Then click the plugin again! As for your file",
|
||||
"此次我们的错误追踪是": "This time our error tracking is",
|
||||
"首先在arxiv上搜索": "First search on arxiv",
|
||||
"被新插件取代": "Replaced by a new plugin",
|
||||
"正在处理文件": "Processing file",
|
||||
"除了连接OpenAI之外": "In addition to connecting OpenAI",
|
||||
"我们检查一下": "Let's check",
|
||||
"进度": "Progress",
|
||||
"处理少数情况下的特殊插件的锁定状态": "Handle the locked state of special plugins in a few cases",
|
||||
"⭐ 开始执行": "⭐ Start execution",
|
||||
"正常情况": "Normal situation",
|
||||
"下个句子中已经说完的部分": "The part that has already been said in the next sentence",
|
||||
"首次运行需要花费较长时间下载NOUGAT参数": "The first run takes a long time to download NOUGAT parameters",
|
||||
"使用tex格式公式 测试2 给出柯西不等式": "Use the tex format formula to test 2 and give the Cauchy inequality",
|
||||
"无法从bing获取信息!": "Unable to retrieve information from Bing!",
|
||||
"秒. 请等待任务完成": "Wait for the task to complete",
|
||||
"开始干正事": "Start doing real work",
|
||||
"需要花费较长时间下载NOUGAT参数": "It takes a long time to download NOUGAT parameters",
|
||||
"然后再次点击该插件": "Then click the plugin again",
|
||||
"受到bing限制": "Restricted by Bing",
|
||||
"检索文章的历史版本的题目": "Retrieve the titles of historical versions of the article",
|
||||
"收尾": "Wrap up",
|
||||
"给定了task": "Given a task",
|
||||
"某段话的整个句子": "The whole sentence of a paragraph",
|
||||
"-=-=-=-=-=-=-=-= 写出HTML文件 -=-=-=-=-=-=-=-=": "-=-=-=-=-=-=-=-= Write out HTML file -=-=-=-=-=-=-=-=",
|
||||
"当前文件": "Current file",
|
||||
"请在输入框内填写需求": "Please fill in the requirements in the input box",
|
||||
"结果是一个字符串": "The result is a string",
|
||||
"用插件实现」": "Implemented with a plugin",
|
||||
"⭐ 到最后一步了": "⭐ Reached the final step",
|
||||
"重新修改当前part的标题": "Modify the title of the current part again",
|
||||
"请勿点击“提交”按钮或者“基础功能区”按钮": "Do not click the 'Submit' button or the 'Basic Function Area' button",
|
||||
"正在执行命令": "Executing command",
|
||||
"检测到**滞留的缓存文档**": "Detected **stuck cache document**",
|
||||
"第三步": "Step three",
|
||||
"失败了~ 别担心": "Failed~ Don't worry",
|
||||
"动态代码解释器": "Dynamic code interpreter",
|
||||
"开始执行": "Start executing",
|
||||
"不给定task": "No task given",
|
||||
"正在加载NOUGAT...": "Loading NOUGAT...",
|
||||
"精准翻译PDF文档": "Accurate translation of PDF documents",
|
||||
"时间限制TIME_LIMIT": "Time limit TIME_LIMIT",
|
||||
"翻译前后混合 -=-=-=-=-=-=-=-=": "Mixed translation before and after -=-=-=-=-=-=-=-=",
|
||||
"搞定代码生成": "Code generation is done",
|
||||
"插件通道": "Plugin channel",
|
||||
"智能体": "Intelligent agent",
|
||||
"切换界面明暗 ☀": "Switch interface brightness ☀",
|
||||
"交换图像的蓝色通道和红色通道": "Swap blue channel and red channel of the image",
|
||||
"作为函数参数": "As a function parameter",
|
||||
"先挑选偶数序列号": "First select even serial numbers",
|
||||
"仅供测试": "For testing only",
|
||||
"执行成功了": "Execution succeeded",
|
||||
"开始逐个文件进行处理": "Start processing files one by one",
|
||||
"当前文件处理列表": "Current file processing list",
|
||||
"执行失败了": "Execution failed",
|
||||
"请及时处理": "Please handle it in time",
|
||||
"源文件": "Source file",
|
||||
"裁剪图像": "Crop image",
|
||||
"插件动态生成插件": "Dynamic generation of plugins",
|
||||
"正在验证上述代码的有效性": "Validating the above code",
|
||||
"⭐ = 关键步骤": "⭐ = Key step",
|
||||
"!= 0 代表“提交”键对话通道": "!= 0 represents the 'Submit' key dialogue channel",
|
||||
"解析python源代码项目": "Parsing Python source code project",
|
||||
"请检查PDF是否损坏": "Please check if the PDF is damaged",
|
||||
"插件动态生成": "Dynamic generation of plugins",
|
||||
"⭐ 分离代码块": "⭐ Separating code blocks",
|
||||
"已经被记忆": "Already memorized",
|
||||
"默认用英文的": "Default to English",
|
||||
"错误追踪": "Error tracking",
|
||||
"对话|编程|学术|智能体": "Dialogue|Programming|Academic|Intelligent agent",
|
||||
"请检查": "Please check",
|
||||
"检测到被滞留的缓存文档": "Detected cached documents being left behind",
|
||||
"还有哪些场合允许使用代理": "What other occasions allow the use of proxies",
|
||||
"1. 如果有文件": "1. If there is a file",
|
||||
"执行开始": "Execution starts",
|
||||
"代码生成结束": "Code generation ends",
|
||||
"请及时点击“**保存当前对话**”获取所有滞留文档": "Please click '**Save Current Dialogue**' in time to obtain all cached documents",
|
||||
"需点击“**函数插件区**”按钮进行处理": "Click the '**Function Plugin Area**' button for processing",
|
||||
"此函数已经弃用": "This function has been deprecated",
|
||||
"以后再写": "Write it later",
|
||||
"返回给定的url解析出的arxiv_id": "Return the arxiv_id parsed from the given URL",
|
||||
"⭐ 文件上传区是否有东西": "⭐ Is there anything in the file upload area",
|
||||
"Nougat解析论文失败": "Nougat failed to parse the paper",
|
||||
"本源代码中": "In this source code",
|
||||
"或者基础功能通道": "Or the basic function channel",
|
||||
"使用zip压缩格式": "Using zip compression format",
|
||||
"受到google限制": "Restricted by Google",
|
||||
"如果是": "If it is",
|
||||
"不用担心": "don't worry"
|
||||
}
|
||||
@@ -1007,7 +1007,6 @@
|
||||
"第一部分": "第1部分",
|
||||
"的分析如下": "の分析は以下の通りです",
|
||||
"解决一个mdx_math的bug": "mdx_mathのバグを解決する",
|
||||
"底部输入区": "下部の入力エリア",
|
||||
"函数插件输入输出接驳区": "関数プラグインの入出力接続エリア",
|
||||
"打开浏览器": "ブラウザを開く",
|
||||
"免费用户填3": "無料ユーザーは3を入力してください",
|
||||
|
||||
@@ -90,5 +90,7 @@
|
||||
"解析PDF_基于GROBID": "ParsePDF_BasedOnGROBID",
|
||||
"虚空终端主路由": "VoidTerminalMainRoute",
|
||||
"批量翻译PDF文档_NOUGAT": "BatchTranslatePDFDocuments_NOUGAT",
|
||||
"解析PDF_基于NOUGAT": "ParsePDF_NOUGAT"
|
||||
"解析PDF_基于NOUGAT": "ParsePDF_NOUGAT",
|
||||
"解析一个Matlab项目": "AnalyzeAMatlabProject",
|
||||
"函数动态生成": "DynamicFunctionGeneration"
|
||||
}
|
||||
@@ -346,7 +346,6 @@
|
||||
"情况会好转": "情況會好轉",
|
||||
"超过512个": "超過512個",
|
||||
"多线": "多線",
|
||||
"底部输入区": "底部輸入區",
|
||||
"合并小写字母开头的段落块并替换为空格": "合併小寫字母開頭的段落塊並替換為空格",
|
||||
"暗色主题": "暗色主題",
|
||||
"提高限制请查询": "提高限制請查詢",
|
||||
|
||||
104
main.py
104
main.py
@@ -2,13 +2,15 @@ import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
||||
|
||||
def main():
|
||||
import gradio as gr
|
||||
if gr.__version__ not in ['3.28.3','3.32.2']: assert False, "需要特殊依赖,请务必用 pip install -r requirements.txt 指令安装依赖,详情信息见requirements.txt"
|
||||
if gr.__version__ not in ['3.32.6']:
|
||||
raise ModuleNotFoundError("使用项目内置Gradio获取最优体验! 请运行 `pip install -r requirements.txt` 指令安装内置Gradio及其他依赖, 详情信息见requirements.txt.")
|
||||
from request_llm.bridge_all import predict
|
||||
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, load_chat_cookies, DummyWith
|
||||
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
||||
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION')
|
||||
CHATBOT_HEIGHT, LAYOUT, AVAIL_LLM_MODELS, AUTO_CLEAR_TXT = get_conf('CHATBOT_HEIGHT', 'LAYOUT', 'AVAIL_LLM_MODELS', 'AUTO_CLEAR_TXT')
|
||||
ENABLE_AUDIO, AUTO_CLEAR_TXT, PATH_LOGGING, AVAIL_THEMES, THEME = get_conf('ENABLE_AUDIO', 'AUTO_CLEAR_TXT', 'PATH_LOGGING', 'AVAIL_THEMES', 'THEME')
|
||||
DARK_MODE, = get_conf('DARK_MODE')
|
||||
|
||||
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
||||
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
||||
@@ -17,8 +19,16 @@ def main():
|
||||
|
||||
initial_prompt = "Serve me as a writing and programming assistant."
|
||||
title_html = f"<h1 align=\"center\">GPT 学术优化 {get_current_version()}</h1>{theme_declaration}"
|
||||
description = "代码开源和更新[地址🚀](https://github.com/binary-husky/gpt_academic),"
|
||||
description += "感谢热情的[开发者们❤️](https://github.com/binary-husky/gpt_academic/graphs/contributors)"
|
||||
description = "Github源代码开源和更新[地址🚀](https://github.com/binary-husky/gpt_academic), "
|
||||
description += "感谢热情的[开发者们❤️](https://github.com/binary-husky/gpt_academic/graphs/contributors)."
|
||||
description += "</br></br>常见问题请查阅[项目Wiki](https://github.com/binary-husky/gpt_academic/wiki), "
|
||||
description += "如遇到Bug请前往[Bug反馈](https://github.com/binary-husky/gpt_academic/issues)."
|
||||
description += "</br></br>普通对话使用说明: 1. 输入问题; 2. 点击提交"
|
||||
description += "</br></br>基础功能区使用说明: 1. 输入文本; 2. 点击任意基础功能区按钮"
|
||||
description += "</br></br>函数插件区使用说明: 1. 输入路径/问题, 或者上传文件; 2. 点击任意函数插件区按钮"
|
||||
description += "</br></br>虚空终端使用说明: 点击虚空终端, 然后根据提示输入指令, 再次点击虚空终端"
|
||||
description += "</br></br>如何保存对话: 点击保存当前的对话按钮"
|
||||
description += "</br></br>如何语音对话: 请阅读Wiki"
|
||||
|
||||
# 问询记录, python 版本建议3.9+(越新越好)
|
||||
import logging, uuid
|
||||
@@ -60,7 +70,7 @@ def main():
|
||||
cancel_handles = []
|
||||
with gr.Blocks(title="GPT 学术优化", theme=set_theme, analytics_enabled=False, css=advanced_css) as demo:
|
||||
gr.HTML(title_html)
|
||||
secret_css, secret_font = gr.Textbox(visible=False), gr.Textbox(visible=False)
|
||||
secret_css, dark_mode = gr.Textbox(visible=False), gr.Textbox(DARK_MODE, visible=False)
|
||||
cookies = gr.State(load_chat_cookies())
|
||||
with gr_L1():
|
||||
with gr_L2(scale=2, elem_id="gpt-chat"):
|
||||
@@ -72,11 +82,11 @@ def main():
|
||||
with gr.Row():
|
||||
txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False)
|
||||
with gr.Row():
|
||||
submitBtn = gr.Button("提交", variant="primary")
|
||||
submitBtn = gr.Button("提交", elem_id="elem_submit", variant="primary")
|
||||
with gr.Row():
|
||||
resetBtn = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm")
|
||||
stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
|
||||
clearBtn = gr.Button("清除", variant="secondary", visible=False); clearBtn.style(size="sm")
|
||||
resetBtn = gr.Button("重置", elem_id="elem_reset", variant="secondary"); resetBtn.style(size="sm")
|
||||
stopBtn = gr.Button("停止", elem_id="elem_stop", variant="secondary"); stopBtn.style(size="sm")
|
||||
clearBtn = gr.Button("清除", elem_id="elem_clear", variant="secondary", visible=False); clearBtn.style(size="sm")
|
||||
if ENABLE_AUDIO:
|
||||
with gr.Row():
|
||||
audio_mic = gr.Audio(source="microphone", type="numpy", streaming=True, show_label=False).style(container=False)
|
||||
@@ -87,7 +97,7 @@ def main():
|
||||
for k in functional:
|
||||
if ("Visible" in functional[k]) and (not functional[k]["Visible"]): continue
|
||||
variant = functional[k]["Color"] if "Color" in functional[k] else "secondary"
|
||||
functional[k]["Button"] = gr.Button(k, variant=variant)
|
||||
functional[k]["Button"] = gr.Button(k, variant=variant, info_str=f'基础功能区: {k}')
|
||||
functional[k]["Button"].style(size="sm")
|
||||
with gr.Accordion("函数插件区", open=True, elem_id="plugin-panel") as area_crazy_fn:
|
||||
with gr.Row():
|
||||
@@ -100,7 +110,9 @@ def main():
|
||||
if not plugin.get("AsButton", True): continue
|
||||
visible = True if match_group(plugin['Group'], DEFAULT_FN_GROUPS) else False
|
||||
variant = plugins[k]["Color"] if "Color" in plugin else "secondary"
|
||||
plugin['Button'] = plugins[k]['Button'] = gr.Button(k, variant=variant, visible=visible).style(size="sm")
|
||||
info = plugins[k].get("Info", k)
|
||||
plugin['Button'] = plugins[k]['Button'] = gr.Button(k, variant=variant,
|
||||
visible=visible, info_str=f'函数插件区: {info}').style(size="sm")
|
||||
with gr.Row():
|
||||
with gr.Accordion("更多函数插件", open=True):
|
||||
dropdown_fn_list = []
|
||||
@@ -117,15 +129,26 @@ def main():
|
||||
switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary").style(size="sm")
|
||||
with gr.Row():
|
||||
with gr.Accordion("点击展开“文件上传区”。上传本地文件/压缩包供函数插件调用。", open=False) as area_file_up:
|
||||
file_upload = gr.Files(label="任何文件, 但推荐上传压缩文件(zip, tar)", file_count="multiple")
|
||||
with gr.Accordion("更换模型 & SysPrompt & 交互界面布局", open=(LAYOUT == "TOP-DOWN"), elem_id="interact-panel"):
|
||||
system_prompt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt)
|
||||
file_upload = gr.Files(label="任何文件, 推荐上传压缩文件(zip, tar)", file_count="multiple", elem_id="elem_upload")
|
||||
|
||||
|
||||
with gr.Floating(init_x="0%", init_y="0%", visible=True, width=None, drag="forbidden"):
|
||||
with gr.Row():
|
||||
with gr.Tab("上传文件", elem_id="interact-panel"):
|
||||
gr.Markdown("请上传本地文件/压缩包供“函数插件区”功能调用。请注意: 上传文件后会自动把输入区修改为相应路径。")
|
||||
file_upload_2 = gr.Files(label="任何文件, 推荐上传压缩文件(zip, tar)", file_count="multiple")
|
||||
|
||||
with gr.Tab("更换模型 & Prompt", elem_id="interact-panel"):
|
||||
md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False)
|
||||
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",)
|
||||
max_length_sl = gr.Slider(minimum=256, maximum=8192, value=4096, step=1, interactive=True, label="Local LLM MaxLength",)
|
||||
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区", "输入清除键", "插件参数区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区")
|
||||
md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False)
|
||||
max_length_sl = gr.Slider(minimum=256, maximum=1024*32, value=4096, step=128, interactive=True, label="Local LLM MaxLength",)
|
||||
system_prompt = gr.Textbox(show_label=True, lines=2, placeholder=f"System Prompt", label="System prompt", value=initial_prompt)
|
||||
|
||||
with gr.Tab("界面外观", elem_id="interact-panel"):
|
||||
theme_dropdown = gr.Dropdown(AVAIL_THEMES, value=THEME, label="更换UI主题").style(container=False)
|
||||
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "浮动输入区", "输入清除键", "插件参数区"],
|
||||
value=["基础功能区", "函数插件区"], label="显示/隐藏功能区", elem_id='cbs').style(container=False)
|
||||
dark_mode_btn = gr.Button("切换界面明暗 ☀", variant="secondary").style(size="sm")
|
||||
dark_mode_btn.click(None, None, None, _js="""() => {
|
||||
if (document.querySelectorAll('.dark').length) {
|
||||
@@ -135,13 +158,17 @@ def main():
|
||||
}
|
||||
}""",
|
||||
)
|
||||
with gr.Tab("帮助", elem_id="interact-panel"):
|
||||
gr.Markdown(description)
|
||||
with gr.Accordion("备选输入区", open=True, visible=False, elem_id="input-panel2") 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():
|
||||
|
||||
with gr.Floating(init_x="20%", init_y="50%", visible=False, width="40%", drag="top") as area_input_secondary:
|
||||
with gr.Accordion("浮动输入区", open=True, elem_id="input-panel2"):
|
||||
with gr.Row() as row:
|
||||
row.style(equal_height=True)
|
||||
with gr.Column(scale=10):
|
||||
txt2 = gr.Textbox(show_label=False, placeholder="Input question here.", lines=8, label="输入区2").style(container=False)
|
||||
with gr.Column(scale=1, min_width=40):
|
||||
submitBtn2 = gr.Button("提交", variant="primary"); submitBtn2.style(size="sm")
|
||||
resetBtn2 = gr.Button("重置", variant="secondary"); resetBtn2.style(size="sm")
|
||||
stopBtn2 = gr.Button("停止", variant="secondary"); stopBtn2.style(size="sm")
|
||||
clearBtn2 = gr.Button("清除", variant="secondary", visible=False); clearBtn2.style(size="sm")
|
||||
@@ -151,12 +178,12 @@ def main():
|
||||
ret = {}
|
||||
ret.update({area_basic_fn: gr.update(visible=("基础功能区" in a))})
|
||||
ret.update({area_crazy_fn: gr.update(visible=("函数插件区" in a))})
|
||||
ret.update({area_input_primary: gr.update(visible=("底部输入区" not in a))})
|
||||
ret.update({area_input_secondary: gr.update(visible=("底部输入区" in a))})
|
||||
ret.update({area_input_primary: gr.update(visible=("浮动输入区" not in a))})
|
||||
ret.update({area_input_secondary: gr.update(visible=("浮动输入区" in a))})
|
||||
ret.update({clearBtn: gr.update(visible=("输入清除键" in a))})
|
||||
ret.update({clearBtn2: gr.update(visible=("输入清除键" in a))})
|
||||
ret.update({plugin_advanced_arg: gr.update(visible=("插件参数区" in a))})
|
||||
if "底部输入区" in a: ret.update({txt: gr.update(value="")})
|
||||
if "浮动输入区" in a: ret.update({txt: gr.update(value="")})
|
||||
return ret
|
||||
checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, txt2, clearBtn, clearBtn2, plugin_advanced_arg] )
|
||||
# 整理反复出现的控件句柄组合
|
||||
@@ -184,6 +211,7 @@ def main():
|
||||
cancel_handles.append(click_handle)
|
||||
# 文件上传区,接收文件后与chatbot的互动
|
||||
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt, txt2, checkboxes, cookies], [chatbot, txt, txt2, cookies])
|
||||
file_upload_2.upload(on_file_uploaded, [file_upload_2, chatbot, txt, txt2, checkboxes, cookies], [chatbot, txt, txt2, cookies])
|
||||
# 函数插件-固定按钮区
|
||||
for k in plugins:
|
||||
if not plugins[k].get("AsButton", True): continue
|
||||
@@ -193,7 +221,8 @@ def main():
|
||||
# 函数插件-下拉菜单与随变按钮的互动
|
||||
def on_dropdown_changed(k):
|
||||
variant = plugins[k]["Color"] if "Color" in plugins[k] else "secondary"
|
||||
ret = {switchy_bt: gr.update(value=k, variant=variant)}
|
||||
info = plugins[k].get("Info", k)
|
||||
ret = {switchy_bt: gr.update(value=k, variant=variant, info_str=f'函数插件区: {info}')}
|
||||
if plugins[k].get("AdvancedArgs", False): # 是否唤起高级插件参数区
|
||||
ret.update({plugin_advanced_arg: gr.update(visible=True, label=f"插件[{k}]的高级参数说明:" + plugins[k].get("ArgsReminder", [f"没有提供高级参数功能说明"]))})
|
||||
else:
|
||||
@@ -266,19 +295,30 @@ def main():
|
||||
cookies.update({'uuid': uuid.uuid4()})
|
||||
return cookies
|
||||
demo.load(init_cookie, inputs=[cookies, chatbot], outputs=[cookies])
|
||||
demo.load(lambda: 0, inputs=None, outputs=None, _js='()=>{GptAcademicJavaScriptInit();}')
|
||||
darkmode_js = """(dark) => {
|
||||
dark = dark == "True";
|
||||
if (document.querySelectorAll('.dark').length) {
|
||||
if (!dark){
|
||||
document.querySelectorAll('.dark').forEach(el => el.classList.remove('dark'));
|
||||
}
|
||||
} else {
|
||||
if (dark){
|
||||
document.querySelector('body').classList.add('dark');
|
||||
}
|
||||
}
|
||||
}"""
|
||||
demo.load(None, inputs=[dark_mode], outputs=None, _js=darkmode_js) # 配置暗色主题或亮色主题
|
||||
demo.load(None, inputs=[gr.Textbox(LAYOUT, visible=False)], outputs=None, _js='(LAYOUT)=>{GptAcademicJavaScriptInit(LAYOUT);}')
|
||||
|
||||
# gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
|
||||
def auto_opentab_delay():
|
||||
import threading, webbrowser, time
|
||||
print(f"如果浏览器没有自动打开,请复制并转到以下URL:")
|
||||
print(f"\t(亮色主题): http://localhost:{PORT}")
|
||||
print(f"\t(暗色主题): http://localhost:{PORT}/?__theme=dark")
|
||||
if DARK_MODE: print(f"\t「暗色主题已启用(支持动态切换主题)」: http://localhost:{PORT}")
|
||||
else: print(f"\t「亮色主题已启用(支持动态切换主题)」: http://localhost:{PORT}")
|
||||
def open():
|
||||
time.sleep(2) # 打开浏览器
|
||||
DARK_MODE, = get_conf('DARK_MODE')
|
||||
if DARK_MODE: webbrowser.open_new_tab(f"http://localhost:{PORT}/?__theme=dark")
|
||||
else: webbrowser.open_new_tab(f"http://localhost:{PORT}")
|
||||
webbrowser.open_new_tab(f"http://localhost:{PORT}")
|
||||
threading.Thread(target=open, name="open-browser", daemon=True).start()
|
||||
threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start()
|
||||
threading.Thread(target=warm_up_modules, name="warm-up", daemon=True).start()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
./docs/gradio-3.32.2-py3-none-any.whl
|
||||
./docs/gradio-3.32.6-py3-none-any.whl
|
||||
pydantic==1.10.11
|
||||
tiktoken>=0.3.3
|
||||
requests[socks]
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
#input-plugin-group .secondary-wrap.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e {
|
||||
border: none;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* hide selector label */
|
||||
#input-plugin-group .svelte-1gfkn6j {
|
||||
visibility: hidden;
|
||||
@@ -82,4 +87,28 @@
|
||||
/* input btns: clear, reset, stop */
|
||||
#input-panel2 button {
|
||||
min-width: min(80px, 100%);
|
||||
}
|
||||
|
||||
|
||||
#cbs {
|
||||
background-color: var(--block-background-fill) !important;
|
||||
}
|
||||
|
||||
#interact-panel .form {
|
||||
border: hidden
|
||||
}
|
||||
|
||||
.drag-area {
|
||||
border: solid;
|
||||
border-width: thin;
|
||||
user-select: none;
|
||||
padding-left: 2%;
|
||||
}
|
||||
|
||||
.floating-component #input-panel2 {
|
||||
border-top-left-radius: 0px;
|
||||
border-top-right-radius: 0px;
|
||||
border: solid;
|
||||
border-width: thin;
|
||||
border-top-width: 0;
|
||||
}
|
||||
@@ -74,13 +74,8 @@ function chatbotContentChanged(attempt = 1, force = false) {
|
||||
}
|
||||
}
|
||||
|
||||
function GptAcademicJavaScriptInit() {
|
||||
chatbotIndicator = gradioApp().querySelector('#gpt-chatbot > div.wrap');
|
||||
var chatbotObserver = new MutationObserver(() => {
|
||||
chatbotContentChanged(1);
|
||||
});
|
||||
chatbotObserver.observe(chatbotIndicator, { attributes: true, childList: true, subtree: true });
|
||||
|
||||
function chatbotAutoHeight(){
|
||||
// 自动调整高度
|
||||
function update_height(){
|
||||
var { panel_height_target, chatbot_height, chatbot } = get_elements(true);
|
||||
if (panel_height_target!=chatbot_height)
|
||||
@@ -110,6 +105,15 @@ function GptAcademicJavaScriptInit() {
|
||||
}, 50); // 每100毫秒执行一次
|
||||
}
|
||||
|
||||
function GptAcademicJavaScriptInit(LAYOUT = "LEFT-RIGHT") {
|
||||
chatbotIndicator = gradioApp().querySelector('#gpt-chatbot > div.wrap');
|
||||
var chatbotObserver = new MutationObserver(() => {
|
||||
chatbotContentChanged(1);
|
||||
});
|
||||
chatbotObserver.observe(chatbotIndicator, { attributes: true, childList: true, subtree: true });
|
||||
if (LAYOUT === "LEFT-RIGHT") {chatbotAutoHeight();}
|
||||
}
|
||||
|
||||
function get_elements(consider_state_panel=false) {
|
||||
var chatbot = document.querySelector('#gpt-chatbot > div.wrap.svelte-18telvq');
|
||||
if (!chatbot) {
|
||||
@@ -118,14 +122,14 @@ function get_elements(consider_state_panel=false) {
|
||||
const panel1 = document.querySelector('#input-panel').getBoundingClientRect();
|
||||
const panel2 = document.querySelector('#basic-panel').getBoundingClientRect()
|
||||
const panel3 = document.querySelector('#plugin-panel').getBoundingClientRect();
|
||||
const panel4 = document.querySelector('#interact-panel').getBoundingClientRect();
|
||||
// const panel4 = document.querySelector('#interact-panel').getBoundingClientRect();
|
||||
const panel5 = document.querySelector('#input-panel2').getBoundingClientRect();
|
||||
const panel_active = document.querySelector('#state-panel').getBoundingClientRect();
|
||||
if (consider_state_panel || panel_active.height < 25){
|
||||
document.state_panel_height = panel_active.height;
|
||||
}
|
||||
// 25 是chatbot的label高度, 16 是右侧的gap
|
||||
var panel_height_target = panel1.height + panel2.height + panel3.height + panel4.height + panel5.height - 25 + 16*3;
|
||||
var panel_height_target = panel1.height + panel2.height + panel3.height + 0 + 0 - 25 + 16*2;
|
||||
// 禁止动态的state-panel高度影响
|
||||
panel_height_target = panel_height_target + (document.state_panel_height-panel_active.height)
|
||||
var panel_height_target = parseInt(panel_height_target);
|
||||
|
||||
@@ -198,7 +198,7 @@
|
||||
}
|
||||
|
||||
/* 小按钮 */
|
||||
.sm.svelte-1ipelgc {
|
||||
.sm {
|
||||
font-family: "Microsoft YaHei UI", "Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui";
|
||||
--button-small-text-weight: 600;
|
||||
--button-small-text-size: 16px;
|
||||
@@ -208,7 +208,7 @@
|
||||
border-top-left-radius: 0px;
|
||||
}
|
||||
|
||||
#plugin-panel .sm.svelte-1ipelgc {
|
||||
#plugin-panel .sm {
|
||||
font-family: "Microsoft YaHei UI", "Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui";
|
||||
--button-small-text-weight: 400;
|
||||
--button-small-text-size: 14px;
|
||||
|
||||
@@ -57,12 +57,9 @@ def adjust_theme():
|
||||
button_cancel_text_color_dark="white",
|
||||
)
|
||||
|
||||
if LAYOUT=="TOP-DOWN":
|
||||
js = ""
|
||||
else:
|
||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
||||
js = f"<script>{f.read()}</script>"
|
||||
|
||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
||||
js = f"<script>{f.read()}</script>"
|
||||
|
||||
# 添加一个萌萌的看板娘
|
||||
if ADD_WAIFU:
|
||||
js += """
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
#plugin-panel .dropdown-arrow.svelte-p5edak {
|
||||
width: 50px;
|
||||
#plugin-panel .dropdown-arrow {
|
||||
width: 25px;
|
||||
}
|
||||
#plugin-panel input.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e {
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
/* 小按钮 */
|
||||
.sm.svelte-1ipelgc {
|
||||
#basic-panel .sm {
|
||||
font-family: "Microsoft YaHei UI", "Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui";
|
||||
--button-small-text-weight: 600;
|
||||
--button-small-text-size: 16px;
|
||||
@@ -27,7 +27,7 @@
|
||||
border-top-left-radius: 6px;
|
||||
}
|
||||
|
||||
#plugin-panel .sm.svelte-1ipelgc {
|
||||
#plugin-panel .sm {
|
||||
font-family: "Microsoft YaHei UI", "Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui";
|
||||
--button-small-text-weight: 400;
|
||||
--button-small-text-size: 14px;
|
||||
|
||||
@@ -57,11 +57,8 @@ def adjust_theme():
|
||||
button_cancel_text_color_dark="white",
|
||||
)
|
||||
|
||||
if LAYOUT=="TOP-DOWN":
|
||||
js = ""
|
||||
else:
|
||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
||||
js = f"<script>{f.read()}</script>"
|
||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
||||
js = f"<script>{f.read()}</script>"
|
||||
|
||||
# 添加一个萌萌的看板娘
|
||||
if ADD_WAIFU:
|
||||
|
||||
@@ -23,12 +23,9 @@ def adjust_theme():
|
||||
if THEME.startswith('huggingface-'): THEME = THEME.lstrip('huggingface-')
|
||||
set_theme = set_theme.from_hub(THEME.lower())
|
||||
|
||||
if LAYOUT=="TOP-DOWN":
|
||||
js = ""
|
||||
else:
|
||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
||||
js = f"<script>{f.read()}</script>"
|
||||
|
||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
||||
js = f"<script>{f.read()}</script>"
|
||||
|
||||
# 添加一个萌萌的看板娘
|
||||
if ADD_WAIFU:
|
||||
js += """
|
||||
|
||||
@@ -73,12 +73,8 @@ def adjust_theme():
|
||||
chatbot_code_background_color_dark="*neutral_950",
|
||||
)
|
||||
|
||||
js = ''
|
||||
if LAYOUT=="TOP-DOWN":
|
||||
js = ""
|
||||
else:
|
||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
||||
js = f"<script>{f.read()}</script>"
|
||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
||||
js = f"<script>{f.read()}</script>"
|
||||
|
||||
# 添加一个萌萌的看板娘
|
||||
if ADD_WAIFU:
|
||||
|
||||
@@ -472,7 +472,7 @@ def extract_archive(file_path, dest_dir):
|
||||
print("Successfully extracted rar archive to {}".format(dest_dir))
|
||||
except:
|
||||
print("Rar format requires additional dependencies to install")
|
||||
return '\n\n解压失败! 需要安装pip install rarfile来解压rar文件'
|
||||
return '\n\n解压失败! 需要安装pip install rarfile来解压rar文件。建议:使用zip压缩格式。'
|
||||
|
||||
# 第三方库,需要预先pip install py7zr
|
||||
elif file_extension == '.7z':
|
||||
@@ -523,7 +523,7 @@ def promote_file_to_downloadzone(file, rename_file=None, chatbot=None):
|
||||
# 把文件复制过去
|
||||
if not os.path.exists(new_path): shutil.copyfile(file, new_path)
|
||||
# 将文件添加到chatbot cookie中,避免多用户干扰
|
||||
if chatbot:
|
||||
if chatbot is not None:
|
||||
if 'files_to_promote' in chatbot._cookies: current = chatbot._cookies['files_to_promote']
|
||||
else: current = []
|
||||
chatbot._cookies.update({'files_to_promote': [new_path] + current})
|
||||
@@ -581,7 +581,7 @@ def on_file_uploaded(request: gradio.Request, files, chatbot, txt, txt2, checkbo
|
||||
|
||||
# 整理文件集合
|
||||
moved_files = [fp for fp in glob.glob(f'{target_path_base}/**/*', recursive=True)]
|
||||
if "底部输入区" in checkboxes:
|
||||
if "浮动输入区" in checkboxes:
|
||||
txt, txt2 = "", target_path_base
|
||||
else:
|
||||
txt, txt2 = target_path_base, ""
|
||||
|
||||
4
version
4
version
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 3.54,
|
||||
"version": 3.55,
|
||||
"show_feature": true,
|
||||
"new_feature": "新增动态代码解释器(CodeInterpreter) <-> 增加文本回答复制按钮 <-> 细分代理场合 <-> 支持动态选择不同界面主题 <-> 提高稳定性&解决多用户冲突问题 <-> 支持插件分类和更多UI皮肤外观 <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率"
|
||||
"new_feature": "重新编译Gradio优化使用体验 <-> 新增动态代码解释器(CodeInterpreter) <-> 增加文本回答复制按钮 <-> 细分代理场合 <-> 支持动态选择不同界面主题 <-> 提高稳定性&解决多用户冲突问题 <-> 支持插件分类和更多UI皮肤外观 <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user