import os import gradio as gr from datasets import load_dataset auth_token = os.environ.get("auth_token") visit_bench_all = load_dataset("mlfoundations/VisIT-Bench", use_auth_token=auth_token) print('visit_bench_all') print(visit_bench_all) print('dataset keys:') print(visit_bench_all.keys()) dataset_keys = list(visit_bench_all.keys()) assert len(dataset_keys) == 1 dataset_key = dataset_keys[0] visit_bench = visit_bench_all[dataset_key] print('first item:') print(visit_bench[0]) df = visit_bench.to_pandas() print(f"Got {len(df)} items in dataframe") df = df.sample(frac=1) df['image'] = df['image'].apply(lambda x: f'') cols = list(df.columns) cols.insert(0, cols.pop(cols.index('image'))) df = df.reindex(columns=cols) LINES_NUMBER = 20 df.drop(columns=['visual'],inplace=True) def display_df(): df_images = df.head(LINES_NUMBER) return df_images def display_next(dataframe, end): start = int(end or len(dataframe)) end = int(start) + int(LINES_NUMBER) global df if end >= len(df) - 1: start = 0 end = LINES_NUMBER df = df.sample(frac=1) print(f"Shuffle") df_images = df.iloc[start:end] assert len(df_images) == LINES_NUMBER return df_images, end initial_dataframe = display_df() # Gradio Blocks with gr.Blocks() as demo: style = """ """ gr.HTML(style) # This line embeds your CSS in the interface gr.Markdown("