POLRAMBORA commited on
Commit
63f6ecc
·
verified ·
1 Parent(s): 72ece84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -200,14 +200,19 @@ with gr.Blocks(css=css) as demo:
200
  history_state = gr.State([])
201
  last_message_state = gr.State("")
202
 
203
- def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
204
- loading_message = history + [(message, "Loading...", "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH)]
205
- yield render_message(loading_message), loading_message, ""
206
-
207
- partial_history = history
208
- for partial_reply in respond(message, api_key, max_tokens, top_p, temperature):
209
- partial_history = history + [(message, partial_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH)]
210
- yield render_message(partial_history), partial_history, ""
 
 
 
 
 
211
 
212
 
213
 
 
200
  history_state = gr.State([])
201
  last_message_state = gr.State("")
202
 
203
+ def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
204
+ loading_message = history + [(message, "Loading...", "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH)]
205
+ yield render_message(loading_message), loading_message, ""
206
+
207
+ assistant_response = ""
208
+ for partial_reply in respond(message, api_key, max_tokens, top_p, temperature):
209
+ assistant_response = partial_reply # Accumulate streamed response
210
+ partial_history = history + [(message, assistant_response, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH)]
211
+ yield render_message(partial_history), partial_history, ""
212
+
213
+ final_history = history + [(message, assistant_response, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH)]
214
+ yield render_message(final_history), final_history, ""
215
+
216
 
217
 
218