From 4cd1f5d71ead0bb5d0bda93d03f6375987c5379c Mon Sep 17 00:00:00 2001 From: w_xiaolizu Date: Sat, 1 Jul 2023 17:33:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=89=8B=E6=9C=BA=E7=AB=AF1.?= =?UTF-8?q?0,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __main__.py | 16 +++++----- crazy_functional.py | 66 ++++++++++++++++++++++++++++++++++++------ docs/assets/custom.css | 18 +++++------- func_box.py | 12 ++++++-- toolbox.py | 15 ++++++---- 5 files changed, 92 insertions(+), 35 deletions(-) diff --git a/__main__.py b/__main__.py index 8ce40ce..9a4e621 100644 --- a/__main__.py +++ b/__main__.py @@ -2,7 +2,7 @@ import os import gradio as gr from request_llm.bridge_all import predict from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_user_upload, \ - get_conf, ArgsGeneralWrapper, DummyWith + get_conf, ArgsGeneralWrapper, DummyWith # 问询记录, python 版本建议3.9+(越新越好) import logging @@ -80,12 +80,12 @@ class ChatBot(ChatBotFrame): with gr.Row(): self.sm_upload = gr.UploadButton(label='UPLOAD', file_count='multiple', elem_classes='sm_btn').style(size='sm', full_width=False) self.sm_code_block = gr.Button(value='CODE', elem_classes='sm_btn').style(size='sm', full_width=False) - self.sm_upload_history = gr.Button("SPASE", variant="primary", elem_classes='sm_btn').style(size='sm') + self.sm_upload_history = gr.Button("SPASE", variant="primary", elem_classes='sm_btn').style(size='sm', full_width=False) + self.md_dropdown = gr.Dropdown(choices=AVAIL_LLM_MODELS, value=LLM_MODEL, + show_label=False, interactive=True, + elem_classes='sm_select', elem_id='change-font-size').style(container=False) gr.HTML(func_box.get_html("appearance_switcher.html").format(label=""), elem_id='user_input_tb', elem_classes="insert_block") - with gr.Column(scale=100): - self.md_dropdown = gr.Dropdown(choices=AVAIL_LLM_MODELS, - value=LLM_MODEL, show_label=False, interactive=True, - elem_classes='sm_select', elem_id='change-font-size').style(container=False) + with gr.Row(): self.txt = gr.Textbox(show_label=False, placeholder="Input question here.", elem_classes='chat_input').style(container=False) self.input_copy = gr.State('') @@ -98,8 +98,8 @@ class ChatBot(ChatBotFrame): fn=lambda: [gr.Tabs.update(selected='plug_tab'), gr.Column.update(visible=False)], inputs=None, outputs=[self.tabs_inputs, self.examples_column] ) self.sm_code_block.click(fn=lambda x: x+'```\n\n```', inputs=[self.txt], outputs=[self.txt]) - self.sm_upload_history.click(get_user_upload, [self.chatbot], outputs=[self.chatbot]).then( - fn=lambda : self.examples_column.update(visible=False), inputs=None, outputs=[self.examples_column]) + self.sm_upload_history.click(get_user_upload, [self.chatbot], outputs=[self.chatbot]).then(fn=lambda: gr.Column.update(visible=False), inputs=None, outputs=self.examples_column) + # self.sm_select_font.select(fn=lambda x: gr.HTML.update(value=f"{x}px"), inputs=[self.sm_select_font], outputs=[self.state_users]) def draw_examples(self): with gr.Column(elem_id='examples_col') as self.examples_column: diff --git a/crazy_functional.py b/crazy_functional.py index c536e82..8c8b077 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -45,6 +45,55 @@ def get_crazy_functions(): "AsButton":False, "Function": HotReload(载入对话历史存档) }, + "Kdocs_多文件转测试用例(输入框输入文档链接)": { + "Color": "primary", + "AsButton": True, + "Function": HotReload(KDOCS_轻文档分析.KDocs_转测试用例), + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "is_show 是否显示过程", # 高级参数输入区的显示提示 + "Parameters": { + "is_show": False, + "prompt": '文档转测试用例', + 'img_ocr': False + } + }, + "需求文档转测试用例(输入框输入需求文档)": { + "Color": "primary", + "AsButton": True, + "Function": HotReload(KDOCS_轻文档分析.需求转测试用例), + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "is_show 是否显示过程", # 高级参数输入区的显示提示 + "Parameters": { + "is_show": False, + "prompt": '文档转测试用例', + 'img_ocr': False, + 'to_markdown': False, + } + }, + "KDocs需求分析问答": { + "Color": "primary", + "AsButton": True, + "Function": HotReload(KDOCS_轻文档分析.KDocs_需求分析问答), + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "is_show 是否显示过程", # 高级参数输入区的显示提示 + "Parameters": { + "is_show": True, + "prompt": '需求分析对话', + 'img_ocr': False, + 'to_markdown': False, + } + }, + "KDocs文档转流程图": { + "Color": "primary", + "AsButton": True, + "Function": HotReload(KDOCS_轻文档分析.KDocs_文档转流程图), + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "is_show 是否显示过程", # 高级参数输入区的显示提示 + "Parameters": { + 'to_markdown': True, + } + }, + "删除所有本地对话历史记录(请谨慎操作)": { "AsButton":False, "Function": HotReload(删除所有本地对话历史记录) @@ -118,9 +167,6 @@ def get_crazy_functions(): "AsButton": False, # 加入下拉菜单中 "Function": HotReload(批量生成函数注释) }, - "保存当前的对话": { - "Function": HotReload(对话历史存档) - }, "[多线程Demo] 解析此项目本身(源码自译解)": { "Function": HotReload(解析项目本身), "AsButton": False, # 加入下拉菜单中 @@ -132,7 +178,8 @@ def get_crazy_functions(): # }, "[插件demo] 历史上的今天": { # HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效 - "Function": HotReload(高阶功能模板函数) + "Function": HotReload(高阶功能模板函数), + "AsButton": False, }, } @@ -152,7 +199,7 @@ def get_crazy_functions(): function_plugins.update({ "批量翻译PDF文档(多线程)": { "Color": "primary", - "AsButton": True, # 加入下拉菜单中 + "AsButton": False, # 加入下拉菜单中 "Function": HotReload(批量翻译PDF文档) }, "询问多个GPT模型": { @@ -422,8 +469,8 @@ def get_crazy_functions(): "Color": "stop", "AsButton": False, "AdvancedArgs": True, - "ArgsReminder": - "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 "+ + "ArgsReminder": + "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 "+ "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + 'If the term "agent" is used in this section, it should be translated to "智能体". ', "Function": HotReload(Latex翻译中文并重新编译PDF) } @@ -433,8 +480,8 @@ def get_crazy_functions(): "Color": "stop", "AsButton": False, "AdvancedArgs": True, - "ArgsReminder": - "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 "+ + "ArgsReminder": + "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 "+ "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + 'If the term "agent" is used in this section, it should be translated to "智能体". ', "Function": HotReload(Latex翻译中文并重新编译PDF) } @@ -456,4 +503,5 @@ def get_crazy_functions(): # except: # print('Load function plugin failed') + ###################### 第n组插件 ########################### return function_plugins diff --git a/docs/assets/custom.css b/docs/assets/custom.css index 7efa80f..d024294 100644 --- a/docs/assets/custom.css +++ b/docs/assets/custom.css @@ -11,7 +11,11 @@ mspace { display: block; } - +@media only screen and (max-width: 767px) { + #column_1 { + display: none !important; + } +} @keyframes highlight { 0%, 100% { border: 2px solid transparent; @@ -37,7 +41,7 @@ mspace { bottom: 0; left: 0; width: 100%; - margin-bottom: 20% !important; + margin-bottom: 30% !important; } #hide_examples { z-index: 0; @@ -77,12 +81,13 @@ mspace { height: 10%; border-radius: 20px!important; min-width: min(10%,100%) !important; + overflow: hidden; } .sm_select { position: relative !important; z-index: 5 !important; bottom: 5px; - width: 20% !important; + min-width: min(20%,100%) !important; border-radius: 20px!important; } .sm_checkbox { @@ -115,13 +120,6 @@ mspace { min-width: min(50px,100%) !important; } - -#sm_btn { - display: flex; - flex-wrap: unset !important; - gap: 5px !important; - width: var(--size-full); -} textarea { resize: none; height: 100%; /* 填充父元素的高度 */ diff --git a/func_box.py b/func_box.py index 5701d64..01814d3 100644 --- a/func_box.py +++ b/func_box.py @@ -588,7 +588,7 @@ def spinner_chatbot_loading(chatbot): return loading_msg -def refresh_load_data(chat, history, prompt, crazy_list): +def refresh_load_data(chat, history, prompt, crazy_list, request: gr.Request): """ Args: chat: 聊天组件 @@ -602,7 +602,15 @@ def refresh_load_data(chat, history, prompt, crazy_list): data = prompt_retrieval(is_all=[is_all]) prompt.samples = data selected = random.sample(crazy_list, 4) - return prompt.update(samples=data, visible=True), prompt, chat, history, gr.Dataset.update(samples=[[i] for i in selected]), selected + user_agent = request.kwargs['headers']['user-agent'].lower() + if user_agent.find('android') != -1 or user_agent.find('iphone') != -1: + hied_elem = gr.update(visible=False) + else: + hied_elem = gr.update() + outputs = [prompt.update(samples=data, visible=True), prompt, + chat, history, gr.Dataset.update(samples=[[i] for i in selected]), selected, + hied_elem, hied_elem] + return outputs diff --git a/toolbox.py b/toolbox.py index 333fd2c..8d63039 100644 --- a/toolbox.py +++ b/toolbox.py @@ -292,11 +292,14 @@ def markdown_convertion(txt): """ pre = '
' suf = '
' - raw_hide = f'
%s
' + raw_pre = '
' + raw_suf = '
' if txt.startswith(pre) and txt.endswith(suf): # print('警告,输入了已经经过转化的字符串,二次转化可能出问题') return txt # 已经被转化过,不需要再次转化 - + if txt.startswith(raw_pre) and txt.endswith(raw_suf): + return txt # 已经被转化过,不需要再次转化 + raw_hide = raw_pre + txt + raw_suf markdown_extension_configs = { 'mdx_math': { 'enable_dollar_delimiter': True, @@ -357,10 +360,10 @@ def markdown_convertion(txt): convert_stage_2_2, n = re.subn(find_equation_pattern, replace_math_render, convert_stage_1_resp, flags=re.DOTALL) # cat them together context = pre + convert_stage_2_1 + f'{split}' + convert_stage_2_2 + suf - return raw_hide.replace('%s', func_box.pattern_html(context)) + context + return raw_hide + context # 破坏html 结构,并显示源码 else: context = pre + markdown.markdown(txt, extensions=['fenced_code', 'codehilite', 'tables', 'sane_lists']) + suf - return raw_hide.replace('%s', func_box.pattern_html(context)) + context + return raw_hide + context # 破坏html 结构,并显示源码 def close_up_code_segment_during_stream(gpt_reply): @@ -514,8 +517,8 @@ def get_user_upload(chatbot, ipaddr: gr.Request): file_link = "
".join([f'{func_box.html_view_blank(f"{root}/{i}")}' for i in file]) history += f'| {count_num} | {root} | {file_link} |\n' count_num += 1 - chatbot.append(['Loading....', - f'[Local Message] 请自行复制以下目录 or 目录+文件, 填入输入框以供函数区高亮按钮使用,' + chatbot.append(['Load Submission History....', + f'[Local Message] 请自行复制以下目录 or 目录+文件, 填入输入框以供函数区高亮按钮使用\n\n' f'{func_box.html_tag_color("提交前记得请检查头尾空格哦~")}\n\n' f'{history}' ])