import os import gradio as gr from datasets import load_dataset val_data_files = {"val": "contextual_val.csv"} contextual_val = load_dataset("ucla-contextual/contextual_val", data_files=val_data_files) print(contextual_val) data = contextual_val['val'] print(data[0]) df = data.to_pandas() df['image'] = df['image_url'].apply(lambda x: ' ') cols = list(df.columns) cols.insert(0, cols.pop(cols.index('image'))) cols.insert(4, cols.pop(cols.index('image_url'))) df = df.reindex(columns=cols) LINES_NUMBER = 20 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: gr.Markdown("