Commit
·
c93bd12
1
Parent(s):
3cae8c2
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import time
|
| 3 |
|
| 4 |
-
def
|
| 5 |
text = "Hello, this is a demo without using streaming that emulates a model"
|
| 6 |
time.sleep(2.4)
|
| 7 |
return text
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
with gr.Blocks() as demo:
|
| 10 |
btn = gr.Button("Generate")
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
def change_visibility():
|
| 14 |
return {
|
| 15 |
-
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
-
btn.click(fn=change_visibility, outputs=
|
| 19 |
-
btn.click(fn=
|
|
|
|
| 20 |
|
| 21 |
demo.launch(debug=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import time
|
| 3 |
|
| 4 |
+
def generate_no_stream():
|
| 5 |
text = "Hello, this is a demo without using streaming that emulates a model"
|
| 6 |
time.sleep(2.4)
|
| 7 |
return text
|
| 8 |
|
| 9 |
+
def generate_streaming():
|
| 10 |
+
text = "Hello, this is a demo without using streaming that emulates a model"
|
| 11 |
+
results = ""
|
| 12 |
+
for word in text.split():
|
| 13 |
+
time.sleep(0.2)
|
| 14 |
+
results += word
|
| 15 |
+
results += " "
|
| 16 |
+
yield results
|
| 17 |
+
|
| 18 |
with gr.Blocks() as demo:
|
| 19 |
btn = gr.Button("Generate")
|
| 20 |
+
out_non_stream = gr.Textbox(label="Non-streaming Generation")
|
| 21 |
+
out_stream = gr.Textbox(label="Streaming Generation")
|
| 22 |
|
| 23 |
def change_visibility():
|
| 24 |
return {
|
| 25 |
+
out_non_stream: gr.update(visible=True),
|
| 26 |
+
out: gr.update(visible=True),
|
| 27 |
}
|
| 28 |
|
| 29 |
+
btn.click(fn=change_visibility, outputs=[out_non_stream, out_stream])
|
| 30 |
+
btn.click(fn=generate_no_stream, outputs=out_non_stream)
|
| 31 |
+
btn.click(fn=generate_streaming, outputs=out_stream)
|
| 32 |
|
| 33 |
demo.launch(debug=True)
|