File size: 985 Bytes
ff252b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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()