artificialguybr commited on
Commit
6ac567d
1 Parent(s): c314120

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -22,21 +22,13 @@ def user(message, history):
22
  history.append([message, ""])
23
  return "", history
24
 
25
- def regenerate(_chatbot, _task_history, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty):
26
- print("Regenerate called") # Debugging line
27
- if not _task_history:
28
- yield _chatbot
29
- return
30
- last_message = _task_history.pop(-1)
31
- _chatbot.pop(-1)
32
- _task_history.append([last_message[0], ""])
33
- new_history, _, _ = chat(_task_history, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty)
34
- print(f"New history: {new_history}") # Debugging line
35
- yield new_history
36
-
37
-
38
-
39
-
40
 
41
  def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
42
  history = history or []
@@ -133,9 +125,11 @@ with gr.Blocks() as demo:
133
 
134
  # Stop button remains the same
135
  stop.click(fn=None, inputs=None, outputs=None, cancels=[submit_click_event], queue=False)
136
-
137
- regen_btn.click(
138
- fn=regenerate, inputs=[chatbot, chat_history_state, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty], outputs=[chatbot], queue=True
 
 
139
  )
140
 
141
 
 
22
  history.append([message, ""])
23
  return "", history
24
 
25
+ def regenerate(history, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty):
26
+ # Remove the last item from the history
27
+ if history:
28
+ history.pop(-1)
29
+
30
+ # Re-execute the chat function
31
+ return chat(history, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty)
 
 
 
 
 
 
 
 
32
 
33
  def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
34
  history = history or []
 
125
 
126
  # Stop button remains the same
127
  stop.click(fn=None, inputs=None, outputs=None, cancels=[submit_click_event], queue=False)
128
+ regen_click_event = regen_btn.click(
129
+ fn=regenerate,
130
+ inputs=[chat_history_state, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty],
131
+ outputs=[chatbot, chat_history_state, message],
132
+ queue=True
133
  )
134
 
135