import utils import gradio as gr # response = response.choices[0].message # print(response) # role = response.role # content = response.content # system, history = messages_to_history(messages + [{'role': role, 'content': content}]) # yield '', history, system with gr.Blocks() as demo: gr.Markdown("""
ChatGLM-4
""") with gr.Row(): with gr.Column(scale=3): system_input = gr.Textbox(value=utils.default_system, lines=1, label='System') with gr.Column(scale=1): modify_system = gr.Button("๐Ÿ› ๏ธ Set system prompt and clear history", scale=2) system_state = gr.Textbox(value=utils.default_system, visible=False) chatbot = gr.Chatbot(label='ChatGLM-4') textbox = gr.Textbox(lines=2, label='Input') with gr.Row(): clear_history = gr.Button("๐Ÿงน Clear history") sumbit = gr.Button("๐Ÿš€ Send") sumbit.click(utils.model_chat, inputs=[textbox, chatbot, system_state], outputs=[textbox, chatbot, system_input], concurrency_limit = 5) clear_history.click(fn=utils.clear_session, inputs=[], outputs=[textbox, chatbot]) modify_system.click(fn=utils.modify_system_session, inputs=[system_input], outputs=[system_state, system_input, chatbot]) demo.queue(api_open=False) demo.launch(max_threads=5)