Spaces:
Runtime error
Runtime error
Fix RETRY_FLAG
Browse files
app.py
CHANGED
@@ -87,7 +87,13 @@ def parse_text(text):
|
|
87 |
|
88 |
|
89 |
def predict(RETRY_FLAG, input, chatbot, max_length, top_p, temperature, history, past_key_values):
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
for response, history, past_key_values in model.stream_chat(tokenizer, input, history, past_key_values=past_key_values,
|
92 |
return_past_key_values=True,
|
93 |
max_length=max_length, top_p=top_p,
|
@@ -212,9 +218,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
212 |
history = gr.State([])
|
213 |
past_key_values = gr.State(None)
|
214 |
|
215 |
-
user_input.submit(predict, [user_input, chatbot, max_length, top_p, temperature, history, past_key_values],
|
216 |
[chatbot, history, past_key_values], show_progress=True)
|
217 |
-
submitBtn.click(predict, [user_input, chatbot, max_length, top_p, temperature, history, past_key_values],
|
218 |
[chatbot, history, past_key_values], show_progress=True, api_name="predict")
|
219 |
submitBtn.click(reset_user_input, [], [user_input])
|
220 |
|
@@ -227,26 +233,31 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
227 |
outputs=[chatbot, history, past_key_values]
|
228 |
)
|
229 |
deleteBtn.click(delete_last_turn, [chatbot, history], [chatbot, history])
|
230 |
-
|
231 |
-
with gr.Accordion("For Translation API", open=False):
|
232 |
-
input_text = gr.Text()
|
233 |
-
tr_btn = gr.Button("Go", variant="primary")
|
234 |
-
out_text = gr.Text()
|
235 |
-
tr_btn.click(trans_api, [input_text, max_length, top_p, temperature], out_text, show_progress=True, api_name="tr")
|
236 |
-
input_text.submit(trans_api, [input_text, max_length, top_p, temperature], out_text, show_progress=True, api_name="tr")
|
237 |
|
238 |
with gr.Accordion("Example inputs", open=True):
|
239 |
examples = gr.Examples(
|
|
|
240 |
examples=[["Explain the plot of Cinderella in a sentence."],
|
241 |
["How long does it take to become proficient in French, and what are the best methods for retaining information?"],
|
242 |
["What are some common mistakes to avoid when writing code?"],
|
243 |
["Build a prompt to generate a beautiful portrait of a horse"],
|
244 |
["Suggest four metaphors to describe the benefits of AI"],
|
245 |
["Write a pop song about leaving home for the sandy beaches."],
|
246 |
-
["Write a summary demonstrating my ability to tame lions"]
|
247 |
-
|
248 |
-
|
249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
# demo.queue().launch(share=False, inbrowser=True)
|
251 |
# demo.queue().launch(share=True, inbrowser=True, debug=True)
|
252 |
|
|
|
87 |
|
88 |
|
89 |
def predict(RETRY_FLAG, input, chatbot, max_length, top_p, temperature, history, past_key_values):
|
90 |
+
try:
|
91 |
+
chatbot.append((parse_text(input), ""))
|
92 |
+
except Exception as exc:
|
93 |
+
logger.error(exc)
|
94 |
+
chatbot[-1] = (parse_text(input), str(exc))
|
95 |
+
yield chatbot, history, past_key_values
|
96 |
+
|
97 |
for response, history, past_key_values in model.stream_chat(tokenizer, input, history, past_key_values=past_key_values,
|
98 |
return_past_key_values=True,
|
99 |
max_length=max_length, top_p=top_p,
|
|
|
218 |
history = gr.State([])
|
219 |
past_key_values = gr.State(None)
|
220 |
|
221 |
+
user_input.submit(predict, [RETRY_FLAG, user_input, chatbot, max_length, top_p, temperature, history, past_key_values],
|
222 |
[chatbot, history, past_key_values], show_progress=True)
|
223 |
+
submitBtn.click(predict, [RETRY_FLAG, user_input, chatbot, max_length, top_p, temperature, history, past_key_values],
|
224 |
[chatbot, history, past_key_values], show_progress=True, api_name="predict")
|
225 |
submitBtn.click(reset_user_input, [], [user_input])
|
226 |
|
|
|
233 |
outputs=[chatbot, history, past_key_values]
|
234 |
)
|
235 |
deleteBtn.click(delete_last_turn, [chatbot, history], [chatbot, history])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
with gr.Accordion("Example inputs", open=True):
|
238 |
examples = gr.Examples(
|
239 |
+
etext = """In America, where cars are an important part of the national psyche, a decade ago people had suddenly started to drive less, which had not happened since the oil shocks of the 1970s. """
|
240 |
examples=[["Explain the plot of Cinderella in a sentence."],
|
241 |
["How long does it take to become proficient in French, and what are the best methods for retaining information?"],
|
242 |
["What are some common mistakes to avoid when writing code?"],
|
243 |
["Build a prompt to generate a beautiful portrait of a horse"],
|
244 |
["Suggest four metaphors to describe the benefits of AI"],
|
245 |
["Write a pop song about leaving home for the sandy beaches."],
|
246 |
+
["Write a summary demonstrating my ability to tame lions"],
|
247 |
+
["鲁迅和周树人什么关系"],
|
248 |
+
["以红楼梦的行文风格写一张委婉的请假条。"],
|
249 |
+
[f"{etext} 翻成中文,列出3个版本"],
|
250 |
+
],
|
251 |
+
inputs = [user_input],
|
252 |
+
)
|
253 |
+
|
254 |
+
with gr.Accordion("For Translation API", open=False):
|
255 |
+
input_text = gr.Text()
|
256 |
+
tr_btn = gr.Button("Go", variant="primary")
|
257 |
+
out_text = gr.Text()
|
258 |
+
tr_btn.click(trans_api, [input_text, max_length, top_p, temperature], out_text, show_progress=True, api_name="tr")
|
259 |
+
input_text.submit(trans_api, [input_text, max_length, top_p, temperature], out_text, show_progress=True, api_name="tr")
|
260 |
+
|
261 |
# demo.queue().launch(share=False, inbrowser=True)
|
262 |
# demo.queue().launch(share=True, inbrowser=True, debug=True)
|
263 |
|