Yuchan5386 commited on
Commit
2704e24
Β·
verified Β·
1 Parent(s): 73f36dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
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
- textbox.submit(chat_stream, inputs=textbox, outputs=output_area)
 
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()