适配手机端1.0,
This commit is contained in:
14
__main__.py
14
__main__.py
@ -80,12 +80,12 @@ class ChatBot(ChatBotFrame):
|
|||||||
with gr.Row():
|
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_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_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)
|
||||||
gr.HTML(func_box.get_html("appearance_switcher.html").format(label=""), elem_id='user_input_tb', elem_classes="insert_block")
|
self.md_dropdown = gr.Dropdown(choices=AVAIL_LLM_MODELS, value=LLM_MODEL,
|
||||||
with gr.Column(scale=100):
|
show_label=False, interactive=True,
|
||||||
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)
|
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.Row():
|
with gr.Row():
|
||||||
self.txt = gr.Textbox(show_label=False, placeholder="Input question here.", elem_classes='chat_input').style(container=False)
|
self.txt = gr.Textbox(show_label=False, placeholder="Input question here.", elem_classes='chat_input').style(container=False)
|
||||||
self.input_copy = gr.State('')
|
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]
|
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_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(
|
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)
|
||||||
fn=lambda : self.examples_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):
|
def draw_examples(self):
|
||||||
with gr.Column(elem_id='examples_col') as self.examples_column:
|
with gr.Column(elem_id='examples_col') as self.examples_column:
|
||||||
|
|||||||
@ -45,6 +45,55 @@ def get_crazy_functions():
|
|||||||
"AsButton":False,
|
"AsButton":False,
|
||||||
"Function": HotReload(载入对话历史存档)
|
"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,
|
"AsButton":False,
|
||||||
"Function": HotReload(删除所有本地对话历史记录)
|
"Function": HotReload(删除所有本地对话历史记录)
|
||||||
@ -118,9 +167,6 @@ def get_crazy_functions():
|
|||||||
"AsButton": False, # 加入下拉菜单中
|
"AsButton": False, # 加入下拉菜单中
|
||||||
"Function": HotReload(批量生成函数注释)
|
"Function": HotReload(批量生成函数注释)
|
||||||
},
|
},
|
||||||
"保存当前的对话": {
|
|
||||||
"Function": HotReload(对话历史存档)
|
|
||||||
},
|
|
||||||
"[多线程Demo] 解析此项目本身(源码自译解)": {
|
"[多线程Demo] 解析此项目本身(源码自译解)": {
|
||||||
"Function": HotReload(解析项目本身),
|
"Function": HotReload(解析项目本身),
|
||||||
"AsButton": False, # 加入下拉菜单中
|
"AsButton": False, # 加入下拉菜单中
|
||||||
@ -132,7 +178,8 @@ def get_crazy_functions():
|
|||||||
# },
|
# },
|
||||||
"[插件demo] 历史上的今天": {
|
"[插件demo] 历史上的今天": {
|
||||||
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
||||||
"Function": HotReload(高阶功能模板函数)
|
"Function": HotReload(高阶功能模板函数),
|
||||||
|
"AsButton": False,
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -152,7 +199,7 @@ def get_crazy_functions():
|
|||||||
function_plugins.update({
|
function_plugins.update({
|
||||||
"批量翻译PDF文档(多线程)": {
|
"批量翻译PDF文档(多线程)": {
|
||||||
"Color": "primary",
|
"Color": "primary",
|
||||||
"AsButton": True, # 加入下拉菜单中
|
"AsButton": False, # 加入下拉菜单中
|
||||||
"Function": HotReload(批量翻译PDF文档)
|
"Function": HotReload(批量翻译PDF文档)
|
||||||
},
|
},
|
||||||
"询问多个GPT模型": {
|
"询问多个GPT模型": {
|
||||||
@ -456,4 +503,5 @@ def get_crazy_functions():
|
|||||||
# except:
|
# except:
|
||||||
# print('Load function plugin failed')
|
# print('Load function plugin failed')
|
||||||
|
|
||||||
|
###################### 第n组插件 ###########################
|
||||||
return function_plugins
|
return function_plugins
|
||||||
|
|||||||
@ -11,7 +11,11 @@
|
|||||||
mspace {
|
mspace {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
@media only screen and (max-width: 767px) {
|
||||||
|
#column_1 {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
@keyframes highlight {
|
@keyframes highlight {
|
||||||
0%, 100% {
|
0%, 100% {
|
||||||
border: 2px solid transparent;
|
border: 2px solid transparent;
|
||||||
@ -37,7 +41,7 @@ mspace {
|
|||||||
bottom: 0;
|
bottom: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-bottom: 20% !important;
|
margin-bottom: 30% !important;
|
||||||
}
|
}
|
||||||
#hide_examples {
|
#hide_examples {
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
@ -77,12 +81,13 @@ mspace {
|
|||||||
height: 10%;
|
height: 10%;
|
||||||
border-radius: 20px!important;
|
border-radius: 20px!important;
|
||||||
min-width: min(10%,100%) !important;
|
min-width: min(10%,100%) !important;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.sm_select {
|
.sm_select {
|
||||||
position: relative !important;
|
position: relative !important;
|
||||||
z-index: 5 !important;
|
z-index: 5 !important;
|
||||||
bottom: 5px;
|
bottom: 5px;
|
||||||
width: 20% !important;
|
min-width: min(20%,100%) !important;
|
||||||
border-radius: 20px!important;
|
border-radius: 20px!important;
|
||||||
}
|
}
|
||||||
.sm_checkbox {
|
.sm_checkbox {
|
||||||
@ -115,13 +120,6 @@ mspace {
|
|||||||
min-width: min(50px,100%) !important;
|
min-width: min(50px,100%) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#sm_btn {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: unset !important;
|
|
||||||
gap: 5px !important;
|
|
||||||
width: var(--size-full);
|
|
||||||
}
|
|
||||||
textarea {
|
textarea {
|
||||||
resize: none;
|
resize: none;
|
||||||
height: 100%; /* 填充父元素的高度 */
|
height: 100%; /* 填充父元素的高度 */
|
||||||
|
|||||||
12
func_box.py
12
func_box.py
@ -588,7 +588,7 @@ def spinner_chatbot_loading(chatbot):
|
|||||||
return loading_msg
|
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:
|
Args:
|
||||||
chat: 聊天组件
|
chat: 聊天组件
|
||||||
@ -602,7 +602,15 @@ def refresh_load_data(chat, history, prompt, crazy_list):
|
|||||||
data = prompt_retrieval(is_all=[is_all])
|
data = prompt_retrieval(is_all=[is_all])
|
||||||
prompt.samples = data
|
prompt.samples = data
|
||||||
selected = random.sample(crazy_list, 4)
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
15
toolbox.py
15
toolbox.py
@ -292,11 +292,14 @@ def markdown_convertion(txt):
|
|||||||
"""
|
"""
|
||||||
pre = '<div class="md-message">'
|
pre = '<div class="md-message">'
|
||||||
suf = '</div>'
|
suf = '</div>'
|
||||||
raw_hide = f'<div class="raw-message hideM">%s</div>'
|
raw_pre = '<div class="raw-message hideM">'
|
||||||
|
raw_suf = '</div>'
|
||||||
if txt.startswith(pre) and txt.endswith(suf):
|
if txt.startswith(pre) and txt.endswith(suf):
|
||||||
# print('警告,输入了已经经过转化的字符串,二次转化可能出问题')
|
# print('警告,输入了已经经过转化的字符串,二次转化可能出问题')
|
||||||
return txt # 已经被转化过,不需要再次转化
|
return txt # 已经被转化过,不需要再次转化
|
||||||
|
if txt.startswith(raw_pre) and txt.endswith(raw_suf):
|
||||||
|
return txt # 已经被转化过,不需要再次转化
|
||||||
|
raw_hide = raw_pre + txt + raw_suf
|
||||||
markdown_extension_configs = {
|
markdown_extension_configs = {
|
||||||
'mdx_math': {
|
'mdx_math': {
|
||||||
'enable_dollar_delimiter': True,
|
'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)
|
convert_stage_2_2, n = re.subn(find_equation_pattern, replace_math_render, convert_stage_1_resp, flags=re.DOTALL)
|
||||||
# cat them together
|
# cat them together
|
||||||
context = pre + convert_stage_2_1 + f'{split}' + convert_stage_2_2 + suf
|
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:
|
else:
|
||||||
context = pre + markdown.markdown(txt, extensions=['fenced_code', 'codehilite', 'tables', 'sane_lists']) + suf
|
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):
|
def close_up_code_segment_during_stream(gpt_reply):
|
||||||
@ -514,8 +517,8 @@ def get_user_upload(chatbot, ipaddr: gr.Request):
|
|||||||
file_link = "<br>".join([f'{func_box.html_view_blank(f"{root}/{i}")}' for i in file])
|
file_link = "<br>".join([f'{func_box.html_view_blank(f"{root}/{i}")}' for i in file])
|
||||||
history += f'| {count_num} | {root} | {file_link} |\n'
|
history += f'| {count_num} | {root} | {file_link} |\n'
|
||||||
count_num += 1
|
count_num += 1
|
||||||
chatbot.append(['Loading....',
|
chatbot.append(['Load Submission History....',
|
||||||
f'[Local Message] 请自行复制以下目录 or 目录+文件, 填入输入框以供函数区高亮按钮使用,'
|
f'[Local Message] 请自行复制以下目录 or 目录+文件, 填入输入框以供函数区高亮按钮使用\n\n'
|
||||||
f'{func_box.html_tag_color("提交前记得请检查头尾空格哦~")}\n\n'
|
f'{func_box.html_tag_color("提交前记得请检查头尾空格哦~")}\n\n'
|
||||||
f'{history}'
|
f'{history}'
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user