onedevelopment commited on
Commit
2f40173
·
1 Parent(s): 3855a0c

Set api_name=False to bypass Gradio 5 info schema crash and use type='messages'

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -167,6 +167,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="gray"), css=custom_css) as demo
167
  elem_id="chatbot",
168
  show_label=False,
169
  bubble_full_width=False,
 
170
  )
171
 
172
  with gr.Row(elem_id="input-container"):
@@ -182,14 +183,18 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="gray"), css=custom_css) as demo
182
 
183
  # Linking components
184
  def chat_echo(message, history):
185
- return "", history + [[message, None]]
 
186
 
187
  def bot_response(history, model_id, system_message, max_tokens, temperature, top_p):
188
- user_message = history[-1][0]
189
 
190
  legacy_history = []
191
- for i in range(len(history) - 1):
192
- legacy_history.append([history[i][0], history[i][1]])
 
 
 
193
 
194
  response_gen = respond(
195
  user_message,
@@ -202,14 +207,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="gray"), css=custom_css) as demo
202
  )
203
 
204
  for partial_response in response_gen:
205
- history[-1][1] = partial_response
206
  yield history
207
 
208
- msg.submit(chat_echo, [msg, chatbot], [msg, chatbot], queue=False).then(
209
- bot_response, [chatbot, model_id, system_message, max_tokens, temperature, top_p], chatbot
210
  )
211
- submit_btn.click(chat_echo, [msg, chatbot], [msg, chatbot], queue=False).then(
212
- bot_response, [chatbot, model_id, system_message, max_tokens, temperature, top_p], chatbot
213
  )
214
 
215
  if __name__ == "__main__":
 
167
  elem_id="chatbot",
168
  show_label=False,
169
  bubble_full_width=False,
170
+ type="messages"
171
  )
172
 
173
  with gr.Row(elem_id="input-container"):
 
183
 
184
  # Linking components
185
  def chat_echo(message, history):
186
+ history.append({"role": "user", "content": message})
187
+ return "", history
188
 
189
  def bot_response(history, model_id, system_message, max_tokens, temperature, top_p):
190
+ user_message = history[-1]["content"]
191
 
192
  legacy_history = []
193
+ for i in range(0, len(history) - 1, 2):
194
+ if i + 1 < len(history):
195
+ legacy_history.append([history[i]["content"], history[i+1]["content"]])
196
+
197
+ history.append({"role": "assistant", "content": ""})
198
 
199
  response_gen = respond(
200
  user_message,
 
207
  )
208
 
209
  for partial_response in response_gen:
210
+ history[-1]["content"] = partial_response
211
  yield history
212
 
213
+ msg.submit(chat_echo, [msg, chatbot], [msg, chatbot], queue=False, api_name=False).then(
214
+ bot_response, [chatbot, model_id, system_message, max_tokens, temperature, top_p], chatbot, api_name=False
215
  )
216
+ submit_btn.click(chat_echo, [msg, chatbot], [msg, chatbot], queue=False, api_name=False).then(
217
+ bot_response, [chatbot, model_id, system_message, max_tokens, temperature, top_p], chatbot, api_name=False
218
  )
219
 
220
  if __name__ == "__main__":