Spaces:
Sleeping
Sleeping
File size: 1,987 Bytes
9a1ab03 de53991 9a1ab03 de53991 9a1ab03 de53991 9a1ab03 1921336 c89910e 5e80f43 de53991 5e80f43 f276c92 5e80f43 a232b31 f276c92 de53991 5e80f43 1921336 de53991 1921336 9a1ab03 de53991 |
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import copy
import random
import gradio as gr
TEST = """ Test of Time. A Benchmark for Evaluating LLMs on Temporal Reasoning. Large language models (LLMs) have
showcased remarkable reasoning capabilities, yet they remain susceptible to errors, particularly in temporal
reasoning tasks involving complex temporal logic. """
def generate_data_test():
"""Generator to yield words"""
temp = copy.deepcopy(TEST)
l1 = temp.split()
random.shuffle(l1)
temp = ' '.join(l1)
for word in temp.split(" "):
yield word + " "
def stream_data(content_list, model):
"""Stream data to three columns"""
outputs = ["" for _ in content_list]
# Use the gen method to handle batch generation
generator = model.streaming(content_list)
while True:
updated = False
try:
id, word = next(generator) # Get the next generated word for the corresponding content
outputs[id] += f"{word} "
updated = True
except StopIteration:
break
if updated:
yield tuple(outputs)
def create_interface():
with gr.Blocks() as demo:
with gr.Group():
with gr.Row():
columns = [gr.Textbox(label=f"Column {i+1}", lines=10) for i in range(3)]
start_btn = gr.Button("Start Streaming")
def start_streaming():
content_list = [col.value for col in columns] # Get input texts from text boxes
for data in stream_data(content_list):
updates = [gr.update(value=data[i]) for i in range(len(columns))]
yield tuple(updates)
start_btn.click(
fn=start_streaming,
inputs=[],
outputs=columns,
show_progress=False
)
return demo
if __name__ == "__main__":
demo = create_interface()
demo.queue()
demo.launch() |