from pathlib import Path import os import gradio as gr from gradio.components.gallery import GalleryImageType import datasets from datasets import load_dataset from huggingface_hub import HfApi, HfFileSystem, login from dotenv import load_dotenv load_dotenv() HF_TOKEN = os.getenv('HF_TOKEN') login(token=HF_TOKEN, add_to_git_credential=True) def stream_dataset_from_hub(split): dataset = load_dataset('mcarthuradal/arm-unicef', data_dir='images', split=split, streaming=True) return dataset dataset = stream_dataset_from_hub('train') def get_images(path: str | Path) -> list[GalleryImageType]: # filenames = os.listdir(path) # image_names = [filename for filename in filenames if filename.endswith('.tif')] n = 50 image_batch = dataset.iter(n) yield image_batch['image'] iface = gr.Interface(fn=get_images, inputs='text', outputs='gallery', title='Aerial Images Gallery', description='A gallery of the train and test data to be used without annotations', analytics_enabled=False, allow_flagging='never', ) gr.Gallery(columns=5, rows=10, min_width=500, allow_preview=True, show_download_button=False, show_share_button=False) iface.launch(inbrowser=True)