| 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_builder('mcarthuradal/arm-unicef') | |
| data = dataset.as_streaming_dataset(split).iter(200) | |
| yield next(data) | |
| stream = stream_dataset_from_hub('train') | |
| def get_images(split: str): | |
| n = 50 | |
| batch = stream['image'][:n] | |
| return batch | |
| 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(debug=True) | |