File size: 1,494 Bytes
a678ce3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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)