ChatGLM4 / app.py
Xianbao QIAN
Add a demo for GLM4, inspired by QWen's demo.
a678ce3
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("""<center><font size=8>ChatGLM-4</center>""")
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)