xu song commited on
Commit
d89d143
β€’
1 Parent(s): 5799733
Files changed (2) hide show
  1. app.py +3 -3
  2. app_util.py +5 -5
app.py CHANGED
@@ -46,7 +46,7 @@ with gr.Blocks() as demo:
46
  chatbot = gr.Chatbot(avatar_images=("assets/man.png", "assets/bot.png"))
47
  with gr.Row():
48
  with gr.Column(scale=4):
49
- # user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=10)
50
  with gr.Row():
51
  generate_btn = gr.Button("πŸ€”οΈ Generate")
52
  retry_btn = gr.Button("πŸ”„ Regenerate")
@@ -86,8 +86,8 @@ with gr.Blocks() as demo:
86
 
87
  clear_btn.click(reset_state, inputs=[system], outputs=[chatbot, history], show_progress="full")
88
 
89
- generate_btn.click(generate, [chatbot, history], outputs=[chatbot, history],
90
- show_progress="full")
91
 
92
  slider_max_new_tokens.change(set_max_tokens, inputs=[slider_max_new_tokens])
93
 
 
46
  chatbot = gr.Chatbot(avatar_images=("assets/man.png", "assets/bot.png"))
47
  with gr.Row():
48
  with gr.Column(scale=4):
49
+ generated_text = gr.Textbox(show_label=False, placeholder="...", lines=10, visible=False)
50
  with gr.Row():
51
  generate_btn = gr.Button("πŸ€”οΈ Generate")
52
  retry_btn = gr.Button("πŸ”„ Regenerate")
 
86
 
87
  clear_btn.click(reset_state, inputs=[system], outputs=[chatbot, history], show_progress="full")
88
 
89
+ generate_btn.click(generate, [chatbot, history], outputs=[generated_text, chatbot, history],
90
+ show_progress="full")
91
 
92
  slider_max_new_tokens.change(set_max_tokens, inputs=[slider_max_new_tokens])
93
 
app_util.py CHANGED
@@ -49,17 +49,17 @@ def generate_response(query, chatbot, history):
49
 
50
  if history[-1]["role"] != "user":
51
  gr.Warning('You should generate or type user-input first.')
52
- yield chatbot, history
53
  else:
54
  streamer = bot.generate_response(history, stream=True)
55
  for response in streamer:
56
  chatbot[-1] = (query, response)
57
- yield chatbot, history
58
 
59
  history.append({"role": "assistant", "content": response})
60
  print(f"chatbot is {chatbot}")
61
  print(f"history is {history}")
62
- yield chatbot, history
63
 
64
 
65
  def generate(chatbot, history):
@@ -68,8 +68,8 @@ def generate(chatbot, history):
68
  elif history[-1]["role"] in ["user", "system"]:
69
  return generate_query(chatbot, history)
70
  else:
71
-
72
- gr.Warning("")
73
 
74
 
75
  def regenerate():
 
49
 
50
  if history[-1]["role"] != "user":
51
  gr.Warning('You should generate or type user-input first.')
52
+ yield None, chatbot, history
53
  else:
54
  streamer = bot.generate_response(history, stream=True)
55
  for response in streamer:
56
  chatbot[-1] = (query, response)
57
+ yield response, chatbot, history
58
 
59
  history.append({"role": "assistant", "content": response})
60
  print(f"chatbot is {chatbot}")
61
  print(f"history is {history}")
62
+ yield response, chatbot, history
63
 
64
 
65
  def generate(chatbot, history):
 
68
  elif history[-1]["role"] in ["user", "system"]:
69
  return generate_query(chatbot, history)
70
  else:
71
+ gr.Warning("bug")
72
+ return
73
 
74
 
75
  def regenerate():