Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -199,26 +199,22 @@ def generate_text_topkp_stream(model, prompt, max_len=100, max_gen=98, p=0.9, k=
|
|
199 |
break
|
200 |
|
201 |
yield decoded_text
|
202 |
-
|
203 |
-
history_text = ""
|
204 |
|
205 |
-
def chat_stream(user_input):
|
206 |
-
global history_text
|
207 |
partial_text = ""
|
208 |
for partial_response in generate_text_topkp_stream(model, user_input):
|
209 |
partial_text = partial_response
|
210 |
-
yield history_text + f"μ¬μ©μ: {user_input}\nKeraLux: {partial_text}\n"
|
211 |
-
|
212 |
-
# μ΅μ’
μλ΅ μ
λ°μ΄νΈ
|
213 |
-
history_text += f"μ¬μ©μ: {user_input}\nKeraLux: {partial_text}\n"
|
214 |
|
215 |
with gr.Blocks() as demo:
|
216 |
gr.Markdown("### π KeraLux Textbot with Streaming")
|
217 |
|
218 |
textbox = gr.Textbox(placeholder="λ©μμ§λ₯Ό μ
λ ₯νμΈμ", lines=1)
|
219 |
output_area = gr.Textbox(label="λν κΈ°λ‘", lines=20, interactive=False)
|
220 |
-
|
221 |
-
|
|
|
222 |
textbox.submit(lambda: "", None, textbox)
|
223 |
|
224 |
demo.launch()
|
|
|
199 |
break
|
200 |
|
201 |
yield decoded_text
|
|
|
|
|
202 |
|
203 |
+
def chat_stream(user_input, history_text):
|
|
|
204 |
partial_text = ""
|
205 |
for partial_response in generate_text_topkp_stream(model, user_input):
|
206 |
partial_text = partial_response
|
207 |
+
yield history_text + f"μ¬μ©μ: {user_input}\nKeraLux: {partial_text}\n", \
|
208 |
+
history_text + f"μ¬μ©μ: {user_input}\nKeraLux: {partial_text}\n"
|
|
|
|
|
209 |
|
210 |
with gr.Blocks() as demo:
|
211 |
gr.Markdown("### π KeraLux Textbot with Streaming")
|
212 |
|
213 |
textbox = gr.Textbox(placeholder="λ©μμ§λ₯Ό μ
λ ₯νμΈμ", lines=1)
|
214 |
output_area = gr.Textbox(label="λν κΈ°λ‘", lines=20, interactive=False)
|
215 |
+
state = gr.State("") # μΈμ
λ³ μ μ₯μ
|
216 |
+
|
217 |
+
textbox.submit(chat_stream, inputs=[textbox, state], outputs=[output_area, state])
|
218 |
textbox.submit(lambda: "", None, textbox)
|
219 |
|
220 |
demo.launch()
|