File size: 1,000 Bytes
fe97494
 
 
c93bd12
4e5f961
0f85923
5198906
fe97494
c93bd12
4e5f961
c93bd12
 
0f85923
c93bd12
 
 
 
1f2cd00
 
c93bd12
 
3cae8c2
 
 
c93bd12
3aa7962
3cae8c2
 
c93bd12
 
1b7bc4b
1f2cd00
a0aa548
1f2cd00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
import time

def generate_no_stream():
    text = "Hello, this is an example without using streaming that emulates a model."
    time.sleep(1.2)
    return text

def generate_streaming():
    text = "Hello, this is an example using streaming that emulates a model ."
    results = ""
    for word in text.split():
        time.sleep(0.1)
        results += word
        results += " "
        yield results

with gr.Blocks() as demo:
    btn = gr.Button("Generate")
    out_non_stream = gr.Textbox(label="Non-streaming Generation")
    out_stream = gr.Textbox(label="Streaming Generation")

    def change_visibility():
        return {
            out_non_stream: gr.update(visible=True),
            out_stream: gr.update(visible=True),
        }

    btn.click(fn=change_visibility, outputs=[out_non_stream, out_stream])
    btn.click(fn=generate_streaming, outputs=out_stream)
    btn.click(fn=generate_no_stream, outputs=out_non_stream)

demo.queue(2)
demo.launch(debug=True)