chansung commited on
Commit
19cbba1
1 Parent(s): c582d61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -17,8 +17,21 @@ generator = get_pretrained_models("7B", "tokenizer", local_rank, world_size)
17
  history = []
18
  simple_history = []
19
 
20
- def chat(user_input):
21
- bot_response = get_output(generator, user_input)[0][len(user_input):]
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  history.append({
24
  "role": "user",
@@ -39,6 +52,9 @@ def chat(user_input):
39
  simple_history[-1] = current_pair
40
  yield simple_history
41
 
 
 
 
42
  with gr.Blocks(css = """#col_container {width: 95%; margin-left: auto; margin-right: auto;}
43
  #chatbot {height: 400px; overflow: auto;}""") as demo:
44
 
@@ -46,7 +62,13 @@ with gr.Blocks(css = """#col_container {width: 95%; margin-left: auto; margin-ri
46
  gr.Markdown(f"## {TITLE}\n\n\n\n{ABSTRACT}")
47
  chatbot = gr.Chatbot(elem_id='chatbot')
48
  textbox = gr.Textbox(placeholder="Enter a prompt")
49
-
50
- textbox.submit(chat, textbox, chatbot)
 
 
 
 
 
 
51
 
52
  demo.queue(api_open=False).launch()
 
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,
24
+ max_gen_len=max_gen_len,
25
+ temperature=temperature,
26
+ top_p=top_p)
27
+
28
+ # remove the first phrase identical to user prompt
29
+ bot_response = bot_response[0][len(user_input):]
30
+ # trip the last phrase
31
+ try:
32
+ bot_response = bot_response[:bot_response.rfind(".")]
33
+ except:
34
+ pass
35
 
36
  history.append({
37
  "role": "user",
 
52
  simple_history[-1] = current_pair
53
  yield simple_history
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
 
 
62
  gr.Markdown(f"## {TITLE}\n\n\n\n{ABSTRACT}")
63
  chatbot = gr.Chatbot(elem_id='chatbot')
64
  textbox = gr.Textbox(placeholder="Enter a prompt")
65
+
66
+ with gr.Accordion("Parameters", open=False):
67
+ max_gen_len = gr.Slider(minimum=20, maximum=512, value=256, step=1, interactive=True, label="Max Genenration Length",)
68
+ top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True, label="Top-p (nucleus sampling)",)
69
+ temperature = gr.Slider(minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
70
+
71
+ textbox.submit(chat, [textbox, top_p, temperature, max_gen_len], chatbot)
72
+ textbox.submit(reset_textbox, [], [textbox])
73
 
74
  demo.queue(api_open=False).launch()