FredZhang7 commited on
Commit
75efb4d
1 Parent(s): 0b066eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -111,7 +111,8 @@ def generator(
111
  )
112
 
113
  instruction = re.sub(r"\n{2,}", "\n", instruction).strip().replace("\r\n", "\n")
114
- if input is not None:
 
115
  input = re.sub(r"\n{2,}", "\n", input).strip().replace("\r\n", "\n")
116
  ctx = generate_prompt(instruction, input, history)
117
  print(ctx + "\n")
@@ -144,7 +145,11 @@ def generator(
144
  tmp = pipeline.decode(all_tokens[out_last:])
145
  if "\ufffd" not in tmp:
146
  out_str += tmp
147
- yield out_str.strip()
 
 
 
 
148
  out_last = i + 1
149
  if "\n\n" in out_str:
150
  break
@@ -220,7 +225,7 @@ with gr.Blocks(title=title) as demo:
220
 
221
  history[-1][1] = ""
222
 
223
- yield generator( # for character in
224
  instruction,
225
  None,
226
  token_count,
@@ -229,9 +234,9 @@ with gr.Blocks(title=title) as demo:
229
  presence_penalty,
230
  count_penalty,
231
  history
232
- )
233
- # history[-1][1] += character
234
- # yield history
235
 
236
  msg.submit(user_msg, [msg, chatbot], [msg, chatbot], queue=False).then(
237
  respond, chatbot, chatbot, api_name="chat"
 
111
  )
112
 
113
  instruction = re.sub(r"\n{2,}", "\n", instruction).strip().replace("\r\n", "\n")
114
+ no_history = (history is None)
115
+ if no_history:
116
  input = re.sub(r"\n{2,}", "\n", input).strip().replace("\r\n", "\n")
117
  ctx = generate_prompt(instruction, input, history)
118
  print(ctx + "\n")
 
145
  tmp = pipeline.decode(all_tokens[out_last:])
146
  if "\ufffd" not in tmp:
147
  out_str += tmp
148
+ if no_history:
149
+ yield out_str.strip()
150
+ else:
151
+ for char in tmp:
152
+ yield char
153
  out_last = i + 1
154
  if "\n\n" in out_str:
155
  break
 
225
 
226
  history[-1][1] = ""
227
 
228
+ for character in generator(
229
  instruction,
230
  None,
231
  token_count,
 
234
  presence_penalty,
235
  count_penalty,
236
  history
237
+ ):
238
+ history[-1][1] += character
239
+ yield history
240
 
241
  msg.submit(user_msg, [msg, chatbot], [msg, chatbot], queue=False).then(
242
  respond, chatbot, chatbot, api_name="chat"