chansung commited on
Commit
afed27d
1 Parent(s): 03f2d3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -15,9 +15,8 @@ local_rank, world_size = setup_model_parallel()
15
  generator = get_pretrained_models("7B", "tokenizer", local_rank, world_size)
16
 
17
  history = []
18
- simple_history = []
19
 
20
- def chat(user_input, top_p, temperature, max_gen_len):
21
  bot_response = get_output(
22
  generator=generator,
23
  prompt=user_input,
@@ -43,22 +42,24 @@ def chat(user_input, top_p, temperature, max_gen_len):
43
  "content": bot_response
44
  })
45
 
46
- simple_history.append((user_input, None))
47
 
48
  response = ""
49
  for word in bot_response.split(" "):
50
  time.sleep(0.1)
51
  response += word + " "
52
  current_pair = (user_input, response)
53
- simple_history[-1] = current_pair
54
- yield simple_history
55
 
56
  def reset_textbox():
57
  return gr.update(value='')
58
 
59
  with gr.Blocks(css = """#col_container {width: 95%; margin-left: auto; margin-right: auto;}
60
  #chatbot {height: 400px; overflow: auto;}""") as demo:
61
-
 
 
62
  with gr.Column(elem_id='col_container'):
63
  gr.Markdown(f"## {TITLE}\n\n\n\n{ABSTRACT}")
64
  chatbot = gr.Chatbot(elem_id='chatbot')
@@ -69,7 +70,7 @@ with gr.Blocks(css = """#col_container {width: 95%; margin-left: auto; margin-ri
69
  top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True, label="Top-p (nucleus sampling)",)
70
  temperature = gr.Slider(minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
71
 
72
- textbox.submit(chat, [textbox, top_p, temperature, max_gen_len], chatbot)
73
  textbox.submit(reset_textbox, [], [textbox])
74
 
75
  demo.queue(api_open=False).launch()
 
15
  generator = get_pretrained_models("7B", "tokenizer", local_rank, world_size)
16
 
17
  history = []
 
18
 
19
+ def chat(user_input, top_p, temperature, max_gen_len, state_chatbot):
20
  bot_response = get_output(
21
  generator=generator,
22
  prompt=user_input,
 
42
  "content": bot_response
43
  })
44
 
45
+ state_chatbot = state_chatbot + [(user_input, None)]
46
 
47
  response = ""
48
  for word in bot_response.split(" "):
49
  time.sleep(0.1)
50
  response += word + " "
51
  current_pair = (user_input, response)
52
+ state_chatbot[-1] = current_pair
53
+ yield state_chatbot, state_chatbot
54
 
55
  def reset_textbox():
56
  return gr.update(value='')
57
 
58
  with gr.Blocks(css = """#col_container {width: 95%; margin-left: auto; margin-right: auto;}
59
  #chatbot {height: 400px; overflow: auto;}""") as demo:
60
+
61
+ state_chatbot = gr.State([])
62
+
63
  with gr.Column(elem_id='col_container'):
64
  gr.Markdown(f"## {TITLE}\n\n\n\n{ABSTRACT}")
65
  chatbot = gr.Chatbot(elem_id='chatbot')
 
70
  top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True, label="Top-p (nucleus sampling)",)
71
  temperature = gr.Slider(minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
72
 
73
+ textbox.submit(chat, [textbox, top_p, temperature, max_gen_len, state_chatbot], [state_chatbot, chatbot])
74
  textbox.submit(reset_textbox, [], [textbox])
75
 
76
  demo.queue(api_open=False).launch()