yuntian-deng commited on
Commit
376bf58
1 Parent(s): 47ae588

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import gradio as gr
2
  import os
3
  import sys
4
- import json
 
5
  import requests
6
  import random
7
  import timeout_decorator
@@ -30,6 +31,8 @@ sys.excepthook = exception_handler
30
  sys.tracebacklimit = 0
31
 
32
  def predict(inputs, top_p, temperature, chat_counter, chatbot, history, request:gr.Request):
 
 
33
  payload = {
34
  "model": MODEL,
35
  "messages": [{"role": "user", "content": f"{inputs}"}],
@@ -114,6 +117,9 @@ def predict(inputs, top_p, temperature, chat_counter, chatbot, history, request:
114
  yield [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ], history, chat_counter, response, gr.update(interactive=False), gr.update(interactive=False) # resembles {chatbot: chat, state: history}
115
  except Exception as e:
116
  print (f'error found: {e}')
 
 
 
117
  yield [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ], history, chat_counter, response, gr.update(interactive=True), gr.update(interactive=True)
118
  print(json.dumps({"chat_counter": chat_counter, "payload": payload, "partial_words": partial_words, "token_counter": token_counter, "counter": counter}))
119
 
 
1
  import gradio as gr
2
  import os
3
  import sys
4
+ import json
5
+ import copy
6
  import requests
7
  import random
8
  import timeout_decorator
 
31
  sys.tracebacklimit = 0
32
 
33
  def predict(inputs, top_p, temperature, chat_counter, chatbot, history, request:gr.Request):
34
+ orig_history = copy.deepcopy(history)
35
+ orig_chat_counter = chat_counter
36
  payload = {
37
  "model": MODEL,
38
  "messages": [{"role": "user", "content": f"{inputs}"}],
 
117
  yield [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ], history, chat_counter, response, gr.update(interactive=False), gr.update(interactive=False) # resembles {chatbot: chat, state: history}
118
  except Exception as e:
119
  print (f'error found: {e}')
120
+ return [(orig_history[i], orig_history[i + 1]) for i in range(0, len(orig_history) - 1, 2) ], orig_history, orig_chat_counter, 'Error! Please try again', gr.update(interactive=True), gr.update(interactive=True)
121
+
122
+
123
  yield [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ], history, chat_counter, response, gr.update(interactive=True), gr.update(interactive=True)
124
  print(json.dumps({"chat_counter": chat_counter, "payload": payload, "partial_words": partial_words, "token_counter": token_counter, "counter": counter}))
125