kevinwang676 commited on
Commit
aa12a9f
·
1 Parent(s): aed8adb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -70,15 +70,13 @@ def parse_text(text):
70
  return text
71
 
72
 
73
- def predict(input, chatbot, max_length, top_p, temperature, history, past_key_values):
74
  chatbot.append((parse_text(input), ""))
75
- for response, history, past_key_values in model.stream_chat(tokenizer, input, history, past_key_values=past_key_values,
76
- return_past_key_values=True,
77
- max_length=max_length, top_p=top_p,
78
- temperature=temperature):
79
- chatbot[-1] = (parse_text(input), parse_text(response))
80
 
81
- yield chatbot, history, past_key_values
82
 
83
 
84
  def reset_user_input():
@@ -86,32 +84,32 @@ def reset_user_input():
86
 
87
 
88
  def reset_state():
89
- return [], [], None
90
 
91
 
92
  with gr.Blocks() as demo:
93
- gr.HTML("""<h1 align="center">ChatGLM2-6B</h1>""")
94
 
95
  chatbot = gr.Chatbot()
96
  with gr.Row():
97
  with gr.Column(scale=4):
98
  with gr.Column(scale=12):
99
- user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=10)
 
100
  with gr.Column(min_width=32, scale=1):
101
  submitBtn = gr.Button("Submit", variant="primary")
102
  with gr.Column(scale=1):
103
  emptyBtn = gr.Button("Clear History")
104
- max_length = gr.Slider(0, 32768, value=8192, step=1.0, label="Maximum length", interactive=True)
105
- top_p = gr.Slider(0, 1, value=0.8, step=0.01, label="Top P", interactive=True)
106
  temperature = gr.Slider(0, 1, value=0.95, step=0.01, label="Temperature", interactive=True)
107
 
108
  history = gr.State([])
109
- past_key_values = gr.State(None)
110
 
111
- submitBtn.click(predict, [user_input, chatbot, max_length, top_p, temperature, history, past_key_values],
112
- [chatbot, history, past_key_values], show_progress=True)
113
  submitBtn.click(reset_user_input, [], [user_input])
114
 
115
- emptyBtn.click(reset_state, outputs=[chatbot, history, past_key_values], show_progress=True)
116
 
117
  demo.launch(show_error=True)
 
70
  return text
71
 
72
 
73
+ def predict(input, chatbot, max_length, top_p, temperature, history):
74
  chatbot.append((parse_text(input), ""))
75
+ for response, history in model.stream_chat(tokenizer, input, history, max_length=max_length, top_p=top_p,
76
+ temperature=temperature):
77
+ chatbot[-1] = (parse_text(input), parse_text(response))
 
 
78
 
79
+ yield chatbot, history
80
 
81
 
82
  def reset_user_input():
 
84
 
85
 
86
  def reset_state():
87
+ return [], []
88
 
89
 
90
  with gr.Blocks() as demo:
91
+ gr.HTML("""<h1 align="center">ChatGLM</h1>""")
92
 
93
  chatbot = gr.Chatbot()
94
  with gr.Row():
95
  with gr.Column(scale=4):
96
  with gr.Column(scale=12):
97
+ user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=10).style(
98
+ container=False)
99
  with gr.Column(min_width=32, scale=1):
100
  submitBtn = gr.Button("Submit", variant="primary")
101
  with gr.Column(scale=1):
102
  emptyBtn = gr.Button("Clear History")
103
+ max_length = gr.Slider(0, 4096, value=2048, step=1.0, label="Maximum length", interactive=True)
104
+ top_p = gr.Slider(0, 1, value=0.7, step=0.01, label="Top P", interactive=True)
105
  temperature = gr.Slider(0, 1, value=0.95, step=0.01, label="Temperature", interactive=True)
106
 
107
  history = gr.State([])
 
108
 
109
+ submitBtn.click(predict, [user_input, chatbot, max_length, top_p, temperature, history], [chatbot, history],
110
+ show_progress=True)
111
  submitBtn.click(reset_user_input, [], [user_input])
112
 
113
+ emptyBtn.click(reset_state, outputs=[chatbot, history], show_progress=True)
114
 
115
  demo.launch(show_error=True)