ffreemt commited on
Commit
1132eaf
1 Parent(s): 2e59878

Update block.load to update buff Textbox

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -3,6 +3,7 @@
3
  import os
4
  import time
5
  from dataclasses import asdict, dataclass
 
6
 
7
  import gradio as gr
8
  from ctransformers import AutoConfig, AutoModelForCausalLM
@@ -18,6 +19,7 @@ if URL is None:
18
  if MOSAICML_API_KEY is None:
19
  raise ValueError("git environment variable must be set")
20
 
 
21
 
22
  def predict0(prompt, bot):
23
  # logger.debug(f"{prompt=}, {bot=}, {timeout=}")
@@ -31,7 +33,7 @@ def predict0(prompt, bot):
31
  for word in generator:
32
  print(word, end="", flush=True)
33
  response += word
34
- buff.value = response
35
  print("")
36
  logger.debug(f"{response=}")
37
  except Exception as exc:
@@ -283,7 +285,7 @@ with gr.Blocks(
283
  )
284
  conversation = Chat()
285
  chatbot = gr.Chatbot().style(height=700) # 500
286
- buff = gr.Textbox()
287
  with gr.Row():
288
  with gr.Column():
289
  msg = gr.Textbox(
@@ -429,6 +431,9 @@ with gr.Blocks(
429
  show_progress="full",
430
  )
431
 
 
 
 
432
  # concurrency_count=5, max_size=20
433
  # max_size=36, concurrency_count=14
434
  block.queue(concurrency_count=5, max_size=20).launch(debug=True)
 
3
  import os
4
  import time
5
  from dataclasses import asdict, dataclass
6
+ from types import SimpleNamespace
7
 
8
  import gradio as gr
9
  from ctransformers import AutoConfig, AutoModelForCausalLM
 
19
  if MOSAICML_API_KEY is None:
20
  raise ValueError("git environment variable must be set")
21
 
22
+ ns = SimpleNamespace(response="")
23
 
24
  def predict0(prompt, bot):
25
  # logger.debug(f"{prompt=}, {bot=}, {timeout=}")
 
33
  for word in generator:
34
  print(word, end="", flush=True)
35
  response += word
36
+ ns.response = response
37
  print("")
38
  logger.debug(f"{response=}")
39
  except Exception as exc:
 
285
  )
286
  conversation = Chat()
287
  chatbot = gr.Chatbot().style(height=700) # 500
288
+ buff = gr.Textbox(show_label=False)
289
  with gr.Row():
290
  with gr.Column():
291
  msg = gr.Textbox(
 
431
  show_progress="full",
432
  )
433
 
434
+ # update buff Textbox
435
+ block.load(lambda: ns.response, [], [buff])
436
+
437
  # concurrency_count=5, max_size=20
438
  # max_size=36, concurrency_count=14
439
  block.queue(concurrency_count=5, max_size=20).launch(debug=True)