artificialguybr commited on
Commit
71a6f99
1 Parent(s): 90981c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -28,15 +28,27 @@ def user(message, history):
28
  history.append([message, ""])
29
  return "", history
30
 
 
 
 
 
 
 
 
 
 
31
  def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
32
  history = history or []
33
 
 
 
 
34
  # A última mensagem do usuário
35
  user_prompt = history[-1][0] if history else ""
36
 
37
  # Preparar a entrada para o modelo
38
  prompt_template = f'''system
39
- {system_message.strip()}
40
  user
41
  {user_prompt}
42
  assistant
@@ -96,6 +108,7 @@ with gr.Blocks(css=CSS) as demo:
96
  submit = gr.Button(value="Send message", variant="secondary", scale=1)
97
  clear = gr.Button(value="New topic", variant="secondary", scale=0)
98
  stop = gr.Button(value="Stop", variant="secondary", scale=0)
 
99
  with gr.Accordion("Show Model Parameters", open=False):
100
  with gr.Row():
101
  with gr.Column():
@@ -113,11 +126,22 @@ with gr.Blocks(css=CSS) as demo:
113
  clear.click(lambda: None, None, chatbot, queue=False)
114
 
115
  submit_click_event = submit.click(
116
- fn=user, inputs=[message, chat_history_state], outputs=[message, chat_history_state], queue=True
117
  ).then(
118
  fn=chat, inputs=[chat_history_state, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty], outputs=[chatbot, chat_history_state, message], queue=True
119
  )
 
 
 
 
 
 
 
120
  stop.click(fn=None, inputs=None, outputs=None, cancels=[submit_click_event], queue=False)
121
 
 
 
 
 
122
  demo.queue(max_size=128, concurrency_count=2)
123
  demo.launch()
 
28
  history.append([message, ""])
29
  return "", history
30
 
31
+ def regenerate(_chatbot, _task_history):
32
+ if not _task_history:
33
+ yield _chatbot
34
+ return
35
+ item = _task_history.pop(-1)
36
+ _chatbot.pop(-1)
37
+ yield from make_prediction(item[0]) # Assuming make_prediction is the function you want to use for regeneration
38
+
39
+
40
  def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
41
  history = history or []
42
 
43
+ # Use BASE_SYSTEM_MESSAGE if system_message is empty
44
+ system_message_to_use = system_message if system_message.strip() else BASE_SYSTEM_MESSAGE
45
+
46
  # A última mensagem do usuário
47
  user_prompt = history[-1][0] if history else ""
48
 
49
  # Preparar a entrada para o modelo
50
  prompt_template = f'''system
51
+ {system_message_to_use.strip()}
52
  user
53
  {user_prompt}
54
  assistant
 
108
  submit = gr.Button(value="Send message", variant="secondary", scale=1)
109
  clear = gr.Button(value="New topic", variant="secondary", scale=0)
110
  stop = gr.Button(value="Stop", variant="secondary", scale=0)
111
+ regen_btn = gr.Button(value="Regenerate", variant="secondary", scale=0)
112
  with gr.Accordion("Show Model Parameters", open=False):
113
  with gr.Row():
114
  with gr.Column():
 
126
  clear.click(lambda: None, None, chatbot, queue=False)
127
 
128
  submit_click_event = submit.click(
129
+ fn=user, inputs=[message, chat_history_state], outputs=[message, chat_history_state], queue=True
130
  ).then(
131
  fn=chat, inputs=[chat_history_state, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty], outputs=[chatbot, chat_history_state, message], queue=True
132
  )
133
+
134
+ # Corrected the clear button click event
135
+ clear.click(
136
+ fn=clear_chat, inputs=[chat_history_state, message], outputs=[chat_history_state, message], queue=False
137
+ )
138
+
139
+ # Stop button remains the same
140
  stop.click(fn=None, inputs=None, outputs=None, cancels=[submit_click_event], queue=False)
141
 
142
+ regen_btn.click(
143
+ fn=regenerate, inputs=[chatbot, chat_history_state], outputs=[chatbot], queue=True
144
+ )
145
+
146
  demo.queue(max_size=128, concurrency_count=2)
147
  demo.launch()