Spaces:
Sleeping
Sleeping
Hannah
commited on
Commit
·
ec40afd
1
Parent(s):
28489d9
add streaming test
Browse files
app.py
CHANGED
@@ -1,33 +1,38 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
def show_tab_one():
|
5 |
-
return gr.Tab(visible=True), gr.Tab(visible=False), gr.Accordion(open=False)
|
6 |
|
7 |
-
|
8 |
-
return gr.Tab(visible=False), gr.Tab(visible=True), gr.Accordion(open=False)
|
9 |
-
|
10 |
-
def show_all_tabs():
|
11 |
-
return gr.Tab(visible=True), gr.Tab(visible=True), gr.Accordion(open=False)
|
12 |
|
13 |
-
|
|
|
14 |
|
15 |
with gr.Blocks() as demo:
|
16 |
-
with gr.
|
17 |
-
with gr.Accordion("
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
21 |
|
22 |
-
with gr.Row():
|
23 |
with gr.Tabs():
|
24 |
-
with gr.Tab(
|
25 |
-
gr.
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
def open_accordion():
|
6 |
+
return gr.Accordion(open=True, label="Test Accordion")
|
7 |
|
8 |
with gr.Blocks() as demo:
|
9 |
+
with gr.Column():
|
10 |
+
with gr.Accordion(label="Test Accordion", open=False) as accordion:
|
11 |
+
temp_slider = gr.Slider(minimum=0, maximum=100,value=50)
|
12 |
+
temp_slider.change(lambda x: x, [temp_slider])
|
13 |
+
|
14 |
+
btn = gr.Button(value="Open Accordion")
|
15 |
+
btn.click(open_accordion, outputs=[accordion])
|
16 |
|
|
|
17 |
with gr.Tabs():
|
18 |
+
with gr.Tab("Chat"):
|
19 |
+
chatbot = gr.Chatbot()
|
20 |
+
msg = gr.Textbox()
|
21 |
+
|
22 |
+
def user(user_message, history):
|
23 |
+
return "", history + [[user_message, None]]
|
24 |
+
|
25 |
+
def bot(history):
|
26 |
+
history[-1][1] = ''
|
27 |
+
for msg in range(0, 10000):
|
28 |
+
history[-1][1] += str(msg)
|
29 |
+
if msg % 100 == 0:
|
30 |
+
history[-1][1] += '\n'
|
31 |
+
time.sleep(0.01)
|
32 |
+
yield history
|
33 |
+
|
34 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
35 |
+
fn=bot, inputs=chatbot, outputs=chatbot, api_name='bot',
|
36 |
+
)
|
37 |
+
|
38 |
+
demo.launch()
|