Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,8 +52,7 @@ def postprocess(text):
|
|
| 52 |
return text
|
| 53 |
|
| 54 |
|
| 55 |
-
def predict(input,
|
| 56 |
-
chatbot.append((postprocess(input), ""))
|
| 57 |
response = ""
|
| 58 |
history.append(input)
|
| 59 |
|
|
@@ -75,12 +74,11 @@ def predict(input, chatbot, max_length, top_p, temperature, history):
|
|
| 75 |
)
|
| 76 |
for response_piece in generator:
|
| 77 |
response += response_piece
|
| 78 |
-
chatbot[-1] = (chatbot[-1][0], postprocess(response))
|
| 79 |
|
| 80 |
-
yield
|
| 81 |
|
| 82 |
history.append(response)
|
| 83 |
-
yield
|
| 84 |
|
| 85 |
|
| 86 |
def reset_user_input():
|
|
@@ -89,7 +87,7 @@ def reset_user_input():
|
|
| 89 |
|
| 90 |
def reset_state():
|
| 91 |
history = gr.State(init_history)
|
| 92 |
-
return
|
| 93 |
|
| 94 |
|
| 95 |
max_length = 2048
|
|
@@ -116,9 +114,8 @@ with gr.Blocks() as demo:
|
|
| 116 |
submitBtn.click(
|
| 117 |
predict, [
|
| 118 |
'請為『%s』選取5個公式' %user_input,
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
[chatbot, history], show_progress=True
|
| 122 |
)
|
| 123 |
submitBtn.click(reset_user_input, [], [user_input])
|
| 124 |
submitBtn.click(reset_user_input, [], [final_sample])
|
|
@@ -128,6 +125,9 @@ with gr.Blocks() as demo:
|
|
| 128 |
'你需要為故事%轉寫一段故事大綱'
|
| 129 |
'提供一個完整的龍骨給之後的編劇用。') %expand,
|
| 130 |
outputs=final_sample)
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
demo.queue().launch(share=False, inbrowser=True)
|
|
|
|
| 52 |
return text
|
| 53 |
|
| 54 |
|
| 55 |
+
def predict(input, max_length, top_p, temperature, history):
|
|
|
|
| 56 |
response = ""
|
| 57 |
history.append(input)
|
| 58 |
|
|
|
|
| 74 |
)
|
| 75 |
for response_piece in generator:
|
| 76 |
response += response_piece
|
|
|
|
| 77 |
|
| 78 |
+
yield postprocess(response), history
|
| 79 |
|
| 80 |
history.append(response)
|
| 81 |
+
yield response, history
|
| 82 |
|
| 83 |
|
| 84 |
def reset_user_input():
|
|
|
|
| 87 |
|
| 88 |
def reset_state():
|
| 89 |
history = gr.State(init_history)
|
| 90 |
+
return '', '', []
|
| 91 |
|
| 92 |
|
| 93 |
max_length = 2048
|
|
|
|
| 114 |
submitBtn.click(
|
| 115 |
predict, [
|
| 116 |
'請為『%s』選取5個公式' %user_input,
|
| 117 |
+
max_length, top_p, temperature, history],
|
| 118 |
+
[five_sample, history], show_progress=True
|
|
|
|
| 119 |
)
|
| 120 |
submitBtn.click(reset_user_input, [], [user_input])
|
| 121 |
submitBtn.click(reset_user_input, [], [final_sample])
|
|
|
|
| 125 |
'你需要為故事%轉寫一段故事大綱'
|
| 126 |
'提供一個完整的龍骨給之後的編劇用。') %expand,
|
| 127 |
outputs=final_sample)
|
| 128 |
+
|
| 129 |
+
emptyBtn.click(reset_state,
|
| 130 |
+
outputs=[five_sample, final_sample, history],
|
| 131 |
+
show_progress=True)
|
| 132 |
|
| 133 |
demo.queue().launch(share=False, inbrowser=True)
|