|
|
import utils |
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|