pcuenq HF staff commited on
Commit
20acbf8
·
1 Parent(s): 5f07eaa

Refresh on empty message, remove autorefresh.

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -36,13 +36,6 @@ def generate_html(me: str) -> str:
36
  return html
37
 
38
 
39
- def refresh(state):
40
- def do_refresh():
41
- print(f"refresh, username: {state.value['username']}")
42
- return generate_html(state.value["username"])
43
- return do_refresh
44
-
45
-
46
  def store_message(writer: str, message: str, me: str):
47
  if writer and message:
48
  with open(DATA_FILE, "a") as csvfile:
@@ -68,7 +61,8 @@ def login(username, state):
68
 
69
  def send_message(message, state):
70
  username = state["username"]
71
- store_message(username, message, me=username)
 
72
  return (generate_html(username), "")
73
 
74
  css = """
@@ -100,10 +94,10 @@ with gr.Blocks(css=css) as demo:
100
 
101
  with (chat_box := gr.Box(visible=False)):
102
  with gr.Row():
103
- output = gr.HTML(refresh(state), label="Chat", every=5.0)
104
  with gr.Row():
105
  message = gr.Textbox(
106
- label="Your message", show_label=False, max_lines=1
107
  )
108
 
109
  username.submit(
@@ -122,4 +116,4 @@ with gr.Blocks(css=css) as demo:
122
  inputs=[message, state],
123
  outputs=[output, message],
124
  )
125
- demo.launch(enable_queue=True)
 
36
  return html
37
 
38
 
 
 
 
 
 
 
 
39
  def store_message(writer: str, message: str, me: str):
40
  if writer and message:
41
  with open(DATA_FILE, "a") as csvfile:
 
61
 
62
  def send_message(message, state):
63
  username = state["username"]
64
+ if message != "":
65
+ store_message(username, message, me=username)
66
  return (generate_html(username), "")
67
 
68
  css = """
 
94
 
95
  with (chat_box := gr.Box(visible=False)):
96
  with gr.Row():
97
+ output = gr.HTML(label="Chat")
98
  with gr.Row():
99
  message = gr.Textbox(
100
+ label="Your message (leave empty to refresh)", show_label=True, max_lines=1
101
  )
102
 
103
  username.submit(
 
116
  inputs=[message, state],
117
  outputs=[output, message],
118
  )
119
+ demo.launch()