yuntian-deng commited on
Commit
520fa8d
1 Parent(s): f427a7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -16
app.py CHANGED
@@ -20,20 +20,6 @@ def exception_handler(exception_type, exception, traceback):
20
  print("%s: %s" % (exception_type.__name__, exception))
21
  sys.excepthook = exception_handler
22
  sys.tracebacklimit = 0
23
-
24
- #https://github.com/gradio-app/gradio/issues/3531#issuecomment-1484029099
25
- def parse_codeblock(text):
26
- lines = text.split("\n")
27
- for i, line in enumerate(lines):
28
- if "```" in line:
29
- if line != "```":
30
- lines[i] = f'<pre><code class="{lines[i][3:]}">'
31
- else:
32
- lines[i] = '</code></pre>'
33
- else:
34
- if i > 0:
35
- lines[i] = "<br/>" + line.replace("<", "&lt;").replace(">", "&gt;")
36
- return "".join(lines)
37
 
38
  def predict(inputs, top_p, temperature, chat_counter, chatbot, history, request:gr.Request):
39
  payload = {
@@ -117,10 +103,10 @@ def predict(inputs, top_p, temperature, chat_counter, chatbot, history, request:
117
  else:
118
  history[-1] = partial_words
119
  token_counter += 1
120
- yield [(parse_codeblock(history[i]), parse_codeblock(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}
121
  except Exception as e:
122
  print (f'error found: {e}')
123
- yield [(parse_codeblock(history[i]), parse_codeblock(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
 
126
 
 
20
  print("%s: %s" % (exception_type.__name__, exception))
21
  sys.excepthook = exception_handler
22
  sys.tracebacklimit = 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def predict(inputs, top_p, temperature, chat_counter, chatbot, history, request:gr.Request):
25
  payload = {
 
103
  else:
104
  history[-1] = partial_words
105
  token_counter += 1
106
+ 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}
107
  except Exception as e:
108
  print (f'error found: {e}')
109
+ 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)
110
  print(json.dumps({"chat_counter": chat_counter, "payload": payload, "partial_words": partial_words, "token_counter": token_counter, "counter": counter}))
111
 
112