Hannah commited on
Commit
ec40afd
·
1 Parent(s): 28489d9

add streaming test

Browse files
Files changed (1) hide show
  1. app.py +32 -27
app.py CHANGED
@@ -1,33 +1,38 @@
1
- import gradio as gr
2
-
3
-
4
- def show_tab_one():
5
- return gr.Tab(visible=True), gr.Tab(visible=False), gr.Accordion(open=False)
6
 
7
- def show_tab_two():
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
- acc_open = False
 
14
 
15
  with gr.Blocks() as demo:
16
- with gr.Row():
17
- with gr.Accordion("Menu. Click to open or close", open=False) as accordion:
18
- btn_1 = gr.Button(value="Show Tab One")
19
- btn_2 = gr.Button(value="Show Tab Two")
20
- btn_3 = gr.Button(value="Show All Tabs")
 
 
21
 
22
- with gr.Row():
23
  with gr.Tabs():
24
- with gr.Tab(label="Tab One", visible=False) as tab_one:
25
- gr.Markdown(value="Tab One")
26
- with gr.Tab(label="Tab two", visible=False) as tab_two:
27
- gr.Markdown(value="Tab two")
28
- btn_1.click(show_tab_one, inputs=None, outputs=[tab_one, tab_two, accordion])
29
- btn_2.click(show_tab_two, inputs=None, outputs=[tab_one, tab_two, accordion])
30
- btn_3.click(show_all_tabs, inputs=None, outputs=[tab_one, tab_two, accordion])
31
-
32
- if __name__ == "__main__":
33
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
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()