解决合并川虎导致 Prompt 重复的bug

This commit is contained in:
w_xiaolizu
2023-06-27 16:39:19 +08:00
parent bd0fd4fd68
commit 61e3945547
2 changed files with 9 additions and 2 deletions

View File

@ -79,6 +79,7 @@ class ChatBot(ChatBotFrame):
with gr.Box(elem_id='chat_box'):
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)
gr.HTML(func_box.get_html("appearance_switcher.html").format(label=""), elem_id='user_input_tb', elem_classes="insert_block")
with gr.Row():
self.txt = gr.Textbox(show_label=False, placeholder="Input question here.", elem_classes='chat_input').style(container=False)
@ -91,6 +92,7 @@ class ChatBot(ChatBotFrame):
self.sm_upload.upload(on_file_uploaded, [self.sm_upload, self.chatbot, self.txt], [self.chatbot, self.txt]).then(
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\n```', inputs=[self.txt], outputs=[self.txt])
def draw_examples(self):
with gr.Column(elem_id='examples_col') as self.examples_column:

View File

@ -504,7 +504,12 @@ def show_prompt_result(index, data: gr.Dataset, chatbot):
def pattern_html(html):
bs = BeautifulSoup(html, 'html.parser')
return bs.get_text(separator='')
md_message = bs.find('div', {'class': 'md-message'})
if md_message:
return md_message.get_text(separator='')
else:
return ""
def thread_write_chat(chatbot, history):
"""
@ -709,4 +714,4 @@ class JsonHandle:
if __name__ == '__main__':
html_local_img("docs/imgs/openai-api-key-billing-paid-account.png")
print(pattern_html('<div class="raw-message hideM">很抱歉,作为一个文</div><div class="md-message"><p>很抱歉,作为一个文</p></div>'))