Attempt to autorefresh
Browse files
app.py
CHANGED
|
@@ -36,6 +36,13 @@ def generate_html(me: str) -> str:
|
|
| 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:
|
|
@@ -93,7 +100,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 93 |
|
| 94 |
with (chat_box := gr.Box(visible=False)):
|
| 95 |
with gr.Row():
|
| 96 |
-
output = gr.HTML(label="Chat",
|
| 97 |
with gr.Row():
|
| 98 |
message = gr.Textbox(
|
| 99 |
label="Your message", show_label=False, max_lines=1
|
|
@@ -115,4 +122,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 115 |
inputs=[message, state],
|
| 116 |
outputs=[output, message],
|
| 117 |
)
|
| 118 |
-
demo.launch()
|
|
|
|
| 36 |
return html
|
| 37 |
|
| 38 |
|
| 39 |
+
def refresh(state):
|
| 40 |
+
def do_refresh():
|
| 41 |
+
print("refresh")
|
| 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:
|
|
|
|
| 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
|
|
|
|
| 122 |
inputs=[message, state],
|
| 123 |
outputs=[output, message],
|
| 124 |
)
|
| 125 |
+
demo.launch(enable_queue=True)
|