kevinwang676 commited on
Commit
eea06fe
·
1 Parent(s): b3b99a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -62
app.py CHANGED
@@ -132,75 +132,75 @@ def gr_hide():
132
  with gr.Blocks() as demo:
133
 
134
  with gr.Tab("和ChatGLM谈天说地"):
135
- if not os.path.isfile('config.json'):
136
- save_config()
137
 
138
- with open('config.json', 'r', encoding='utf-8') as f:
139
- configs = json.loads(f.read())
140
 
141
- gr.Markdown('''# <center>🥳 滔滔AI 🎶</center>
142
 
143
  ### <center>🥰 - 滔滔AI,让有爱的AI滔滔不绝</center>
144
  ### <center>🦄 - TalkTalkAI, let lovely AI brighten the future</center>
145
 
146
- ''')
147
-
148
- with gr.Row():
149
- max_length = gr.Slider(minimum=4.0, maximum=4096.0, step=4.0, label='Max Length', value=configs['max_length'])
150
- top_p = gr.Slider(minimum=0.01, maximum=1.0, step=0.01, label='Top P', value=configs['top_p'])
151
- temperature = gr.Slider(minimum=0.01, maximum=2.0, step=0.01, label='Temperature', value=configs['temperature'])
152
- memory_limit = gr.Slider(minimum=0.0, maximum=20.0, step=1.0, label='Memory Limit', value=configs['memory_limit'])
153
- save_conf = gr.Button('保存设置', visible=False)
154
-
155
- gr.Markdown('''<h2>Hint: click on a chat bubble to edit chat history</h2>''')
156
-
157
- state = gr.State([])
158
- chatbot = gr.Chatbot(elem_id='chatbot', show_label=False)
159
- with gr.Row(visible=False) as edit_log:
160
- with gr.Column():
161
- log = gr.Textbox()
162
- with gr.Row():
163
- submit_log = gr.Button('保存')
164
- cancel_log = gr.Button('取消')
165
- log_idx = gr.State([])
166
-
167
- message = gr.Textbox(placeholder='Input your message', label='Q:')
168
-
169
- with gr.Row():
170
- submit = gr.Button('Submit')
171
- edit = gr.Button('Edit last question')
172
- regen = gr.Button('Re-generate')
173
-
174
- delete = gr.Button('Reset chat')
175
-
176
- with gr.Row(visible=False):
177
- save = gr.Button('保存对话(在 `log` 文件夹下)')
178
- load = gr.UploadButton('读取对话', file_types=['file'], file_count='single')
179
-
180
- input_list = [message, chatbot, state, max_length, top_p, temperature, memory_limit]
181
- output_list = [chatbot, state, message]
182
- edit_list = [edit_log, log, log_idx]
183
-
184
- save_conf.click(save_config, inputs=input_list[3:])
185
- load.upload(load_history, inputs=[load, chatbot, state], outputs=output_list + edit_list)
186
- save.click(save_history, inputs=[state])
187
- message.submit(chat_wrapper, inputs=input_list, outputs=output_list + edit_list)
188
- submit.click(chat_wrapper, inputs=input_list, outputs=output_list + edit_list)
189
- edit.click(edit_wrapper, inputs=input_list[1:3], outputs=output_list + edit_list)
190
- regen.click(regenerate_wrapper, inputs=input_list[1:], outputs=output_list + edit_list)
191
- delete.click(reset_history, outputs=output_list + edit_list)
192
- chatbot.select(gr_show_and_load, inputs=[state], outputs=edit_list)
193
- edit_kwargs = {'inputs': [chatbot, state, log, log_idx], 'outputs': [chatbot, state] + edit_list}
194
- log.submit(update_history, **edit_kwargs)
195
- submit_log.click(update_history, **edit_kwargs)
196
- cancel_log.click(gr_hide, outputs=edit_list)
197
 
198
- gr.HTML('''
199
  <div class="footer">
200
- <p>🖼️💕🎡 - 滔滔AI,为爱滔滔
201
  </p>
202
  </div>
203
- ''')
204
 
205
  with gr.Tab("发现更多有趣功能"):
206
 
@@ -223,12 +223,13 @@ with gr.Blocks() as demo:
223
  )
224
 
225
 
226
- gr.HTML('''
227
  <div class="footer">
228
- <p>🖼️💕🎡 - 滔滔AI,为爱滔滔
229
  </p>
 
230
  </div>
231
- ''')
232
 
233
  if __name__ == '__main__':
234
  demo.queue(concurrency_count=5, max_size=20).launch(debug=True)
 
132
  with gr.Blocks() as demo:
133
 
134
  with gr.Tab("和ChatGLM谈天说地"):
135
+ if not os.path.isfile('config.json'):
136
+ save_config()
137
 
138
+ with open('config.json', 'r', encoding='utf-8') as f:
139
+ configs = json.loads(f.read())
140
 
141
+ gr.Markdown('''# <center>🥳 滔滔AI 🎶</center>
142
 
143
  ### <center>🥰 - 滔滔AI,让有爱的AI滔滔不绝</center>
144
  ### <center>🦄 - TalkTalkAI, let lovely AI brighten the future</center>
145
 
146
+ ''')
147
+
148
+ with gr.Row():
149
+ max_length = gr.Slider(minimum=4.0, maximum=4096.0, step=4.0, label='Max Length', value=configs['max_length'])
150
+ top_p = gr.Slider(minimum=0.01, maximum=1.0, step=0.01, label='Top P', value=configs['top_p'])
151
+ temperature = gr.Slider(minimum=0.01, maximum=2.0, step=0.01, label='Temperature', value=configs['temperature'])
152
+ memory_limit = gr.Slider(minimum=0.0, maximum=20.0, step=1.0, label='Memory Limit', value=configs['memory_limit'])
153
+ save_conf = gr.Button('保存设置', visible=False)
154
+
155
+ gr.Markdown('''<h2>Hint: click on a chat bubble to edit chat history</h2>''')
156
+
157
+ state = gr.State([])
158
+ chatbot = gr.Chatbot(elem_id='chatbot', show_label=False)
159
+ with gr.Row(visible=False) as edit_log:
160
+ with gr.Column():
161
+ log = gr.Textbox()
162
+ with gr.Row():
163
+ submit_log = gr.Button('保存')
164
+ cancel_log = gr.Button('取消')
165
+ log_idx = gr.State([])
166
+
167
+ message = gr.Textbox(placeholder='Input your message', label='Q:')
168
+
169
+ with gr.Row():
170
+ submit = gr.Button('Submit')
171
+ edit = gr.Button('Edit last question')
172
+ regen = gr.Button('Re-generate')
173
+
174
+ delete = gr.Button('Reset chat')
175
+
176
+ with gr.Row(visible=False):
177
+ save = gr.Button('保存对话(在 `log` 文件夹下)')
178
+ load = gr.UploadButton('读取对话', file_types=['file'], file_count='single')
179
+
180
+ input_list = [message, chatbot, state, max_length, top_p, temperature, memory_limit]
181
+ output_list = [chatbot, state, message]
182
+ edit_list = [edit_log, log, log_idx]
183
+
184
+ save_conf.click(save_config, inputs=input_list[3:])
185
+ load.upload(load_history, inputs=[load, chatbot, state], outputs=output_list + edit_list)
186
+ save.click(save_history, inputs=[state])
187
+ message.submit(chat_wrapper, inputs=input_list, outputs=output_list + edit_list)
188
+ submit.click(chat_wrapper, inputs=input_list, outputs=output_list + edit_list)
189
+ edit.click(edit_wrapper, inputs=input_list[1:3], outputs=output_list + edit_list)
190
+ regen.click(regenerate_wrapper, inputs=input_list[1:], outputs=output_list + edit_list)
191
+ delete.click(reset_history, outputs=output_list + edit_list)
192
+ chatbot.select(gr_show_and_load, inputs=[state], outputs=edit_list)
193
+ edit_kwargs = {'inputs': [chatbot, state, log, log_idx], 'outputs': [chatbot, state] + edit_list}
194
+ log.submit(update_history, **edit_kwargs)
195
+ submit_log.click(update_history, **edit_kwargs)
196
+ cancel_log.click(gr_hide, outputs=edit_list)
197
 
198
+ gr.HTML('''
199
  <div class="footer">
200
+ <p>🖼️💕🎡 - 滔滔AI,为爱滔滔;有意清秋入衡霍,为君无尽写江天
201
  </p>
202
  </div>
203
+ ''')
204
 
205
  with gr.Tab("发现更多有趣功能"):
206
 
 
223
  )
224
 
225
 
226
+ gr.HTML('''
227
  <div class="footer">
228
+ <p>🖼️💕🎡 - 滔滔AI,为爱滔滔;有意清秋入衡霍,为君无尽写江天
229
  </p>
230
+
231
  </div>
232
+ ''')
233
 
234
  if __name__ == '__main__':
235
  demo.queue(concurrency_count=5, max_size=20).launch(debug=True)