FredZhang7 commited on
Commit
d6d3be5
1 Parent(s): 7f2eab1

generator doesn't work on chatbot?

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -59,7 +59,8 @@ def evaluate(
59
  token_stop = [0]) # stop generation whenever you see any token here
60
 
61
  instruction = re.sub(r'\n{2,}', '\n', instruction).strip().replace('\r\n','\n')
62
- if input is not None:
 
63
  input = re.sub(r'\n{2,}', '\n', input).strip().replace('\r\n','\n')
64
  ctx = generate_prompt(instruction, input, history) # pass the history to the generate_prompt function
65
  print(ctx + "\n")
@@ -88,7 +89,8 @@ def evaluate(
88
  tmp = pipeline.decode(all_tokens[out_last:])
89
  if '\ufffd' not in tmp:
90
  out_str += tmp
91
- yield instruction, out_str.strip()
 
92
  out_last = i + 1
93
  if '\n\n' in out_str:
94
  break
@@ -96,8 +98,10 @@ def evaluate(
96
  del out
97
  del state
98
  gc.collect()
99
- # yield out_str.strip()
100
- yield instruction, out_str.strip()
 
 
101
 
102
  def user(message, chatbot):
103
  chatbot = chatbot or []
@@ -163,7 +167,7 @@ with gr.Blocks(title=title) as demo:
163
  with gr.Row():
164
  with gr.Column():
165
  instruction = gr.Textbox(lines=2, label="Instruction", value='東京で訪れるべき素晴らしい場所とその紹介をいくつか挙げてください。')
166
- input_instruct = gr.Textbox(lines=2, label="Input", placeholder="")
167
  token_count_instruct = gr.Slider(10, 512, label="Max Tokens", step=10, value=333)
168
  temperature_instruct = gr.Slider(0.2, 2.0, label="Temperature", step=0.1, value=1.2)
169
  top_p_instruct = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.3)
 
59
  token_stop = [0]) # stop generation whenever you see any token here
60
 
61
  instruction = re.sub(r'\n{2,}', '\n', instruction).strip().replace('\r\n','\n')
62
+ use_input = (input is not None)
63
+ if use_input:
64
  input = re.sub(r'\n{2,}', '\n', input).strip().replace('\r\n','\n')
65
  ctx = generate_prompt(instruction, input, history) # pass the history to the generate_prompt function
66
  print(ctx + "\n")
 
89
  tmp = pipeline.decode(all_tokens[out_last:])
90
  if '\ufffd' not in tmp:
91
  out_str += tmp
92
+ if use_input:
93
+ yield out_str.strip()
94
  out_last = i + 1
95
  if '\n\n' in out_str:
96
  break
 
98
  del out
99
  del state
100
  gc.collect()
101
+ if use_input:
102
+ yield out_str.strip()
103
+ else:
104
+ return instruction, out_str.strip()
105
 
106
  def user(message, chatbot):
107
  chatbot = chatbot or []
 
167
  with gr.Row():
168
  with gr.Column():
169
  instruction = gr.Textbox(lines=2, label="Instruction", value='東京で訪れるべき素晴らしい場所とその紹介をいくつか挙げてください。')
170
+ input_instruct = gr.Textbox(lines=2, label="Input", placeholder="", value="")
171
  token_count_instruct = gr.Slider(10, 512, label="Max Tokens", step=10, value=333)
172
  temperature_instruct = gr.Slider(0.2, 2.0, label="Temperature", step=0.1, value=1.2)
173
  top_p_instruct = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.3)