import gradio as gr from datasets import load_dataset startimg = 0 def get_dataset_forward(): global startimg final = [] dataset = load_dataset("ShoukanLabs/OpenNiji-Dataset", split=f"train[{startimg}:{startimg + 50}]") for idx in dataset: print(idx) url = dataset["url"] prompt = dataset["prompt"] style = dataset["style"] final.append((url, f"{prompt}\n\n Style: {style}")) startimg += 50 return final def get_dataset_back(): global startimg final = [] startimg -= 50 dataset = load_dataset("ShoukanLabs/OpenNiji-Dataset", split=f"train[{startimg}:{startimg + 50}]") for idx in dataset: url = dataset["url"] prompt = dataset["prompt"] style = dataset["style"] final.append((url, f"{prompt}\n\n Style: {style}")) return final with gr.Blocks() as demo: with gr.Column(): with gr.Row(): back = gr.Button("<").style() forward = gr.Button(">").style() gallery = gr.Gallery( label="Showing 50 images", show_label=True, elem_id="gallery" ).style(object_fit="contain", columns=[10], height="auto") back.click(get_dataset_back, None, gallery) forward.click(get_dataset_forward, None, gallery) if __name__ == "__main__": demo.launch()