Spaces:
Runtime error
Runtime error
import gradio as gr | |
import time | |
import itertools | |
# First stream: Generates numbers from 0 to 9 | |
def stream_numbers(): | |
for i in range(10): | |
time.sleep(1) | |
yield i | |
return 5 | |
return 69 | |
# Second stream: Generates squares of numbers from 0 to 5 (intentionally shorter) | |
def stream_squares(): | |
for i in range(6): | |
time.sleep(1) | |
yield i * i | |
return 5 | |
return 69 | |
def interface_func(): | |
numbers = stream_numbers() | |
squares = stream_squares() | |
for _ in range(10): | |
num = None | |
sqr = None | |
try: | |
num = next(numbers) | |
except StopIteration: | |
pass | |
try: | |
sqr = next(squares) | |
except StopIteration: | |
pass | |
yield (str(num) if num is not None else "Finished", | |
str(sqr) if sqr is not None else "Finished") | |
demo = gr.Interface( | |
fn=interface_func, | |
inputs=[], | |
outputs=["text", "text"] | |
) | |
demo.queue().launch() | |