Spaces:
Sleeping
Sleeping
add retry button
Browse files
app.py
CHANGED
|
@@ -115,6 +115,14 @@ def predict(question, history=[], behavior=[]):
|
|
| 115 |
return "", history, response
|
| 116 |
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
with gr.Blocks() as demo:
|
| 119 |
|
| 120 |
examples_txt = [
|
|
@@ -159,12 +167,14 @@ with gr.Blocks() as demo:
|
|
| 159 |
txt = gr.Textbox(show_label=False, placeholder="输入你想让ChatGPT回答的问题").style(container=False)
|
| 160 |
with gr.Row():
|
| 161 |
button_gen = gr.Button("Submit")
|
|
|
|
| 162 |
button_clr = gr.Button("Clear")
|
| 163 |
|
| 164 |
gr.Examples(examples=examples_bhv, inputs=bhv, label="Examples for setting behavior")
|
| 165 |
gr.Examples(examples=examples_txt, inputs=txt, label="Examples for asking question")
|
| 166 |
txt.submit(predict, [txt, state, behavior], [txt, state, chatbot])
|
| 167 |
button_gen.click(fn=predict, inputs=[txt, state, behavior], outputs=[txt, state, chatbot])
|
|
|
|
| 168 |
button_clr.click(fn=lambda :([],[]), inputs=None, outputs=[chatbot, state])
|
| 169 |
|
| 170 |
demo.launch()
|
|
|
|
| 115 |
return "", history, response
|
| 116 |
|
| 117 |
|
| 118 |
+
def retry(question, history=[], behavior=[]):
|
| 119 |
+
if len(history)<2:
|
| 120 |
+
return "", history, []
|
| 121 |
+
question = history[-2]
|
| 122 |
+
history = history[:-2]
|
| 123 |
+
return predict(question, history, behavior)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
with gr.Blocks() as demo:
|
| 127 |
|
| 128 |
examples_txt = [
|
|
|
|
| 167 |
txt = gr.Textbox(show_label=False, placeholder="输入你想让ChatGPT回答的问题").style(container=False)
|
| 168 |
with gr.Row():
|
| 169 |
button_gen = gr.Button("Submit")
|
| 170 |
+
button_rtr = gr.Button("Retry")
|
| 171 |
button_clr = gr.Button("Clear")
|
| 172 |
|
| 173 |
gr.Examples(examples=examples_bhv, inputs=bhv, label="Examples for setting behavior")
|
| 174 |
gr.Examples(examples=examples_txt, inputs=txt, label="Examples for asking question")
|
| 175 |
txt.submit(predict, [txt, state, behavior], [txt, state, chatbot])
|
| 176 |
button_gen.click(fn=predict, inputs=[txt, state, behavior], outputs=[txt, state, chatbot])
|
| 177 |
+
button_rtr.click(fn=retry, inputs=[txt, state, behavior], outputs=[txt, state, chatbot])
|
| 178 |
button_clr.click(fn=lambda :([],[]), inputs=None, outputs=[chatbot, state])
|
| 179 |
|
| 180 |
demo.launch()
|