mcarthuradal commited on
Commit
bbe297f
1 Parent(s): 20272b4

test gallery

Browse files
Files changed (1) hide show
  1. app.py +47 -4
app.py CHANGED
@@ -1,7 +1,50 @@
 
 
1
  import gradio as gr
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import os
3
  import gradio as gr
4
+ from gradio.components.gallery import GalleryImageType
5
+ import datasets
6
+ from datasets import load_dataset
7
+ from huggingface_hub import HfApi, HfFileSystem, login
8
+ from dotenv import load_dotenv
9
 
10
+ load_dotenv()
11
+ HF_TOKEN = os.getenv('HF_TOKEN')
12
 
13
+ login(token=HF_TOKEN, add_to_git_credential=True)
14
+
15
+
16
+ def stream_dataset_from_hub(split):
17
+ dataset = load_dataset('mcarthuradal/arm-unicef',
18
+ data_dir='images',
19
+ split=split,
20
+ streaming=True)
21
+ return dataset
22
+
23
+
24
+ dataset = stream_dataset_from_hub('train')
25
+
26
+
27
+ def get_images(path: str | Path) -> list[GalleryImageType]:
28
+ # filenames = os.listdir(path)
29
+
30
+ # image_names = [filename for filename in filenames if filename.endswith('.tif')]
31
+ n = 50
32
+ image_batch = dataset.iter(n)
33
+
34
+ yield image_batch['image']
35
+
36
+
37
+ iface = gr.Interface(fn=get_images,
38
+ outputs='gallery',
39
+ title='Aerial Images Gallery',
40
+ description='A gallery of the train and test data to be used without annotations',
41
+ analytics_enabled=False,
42
+ allow_flagging='never', )
43
+ gr.Gallery(columns=5,
44
+ rows=10,
45
+ min_width=500,
46
+ allow_preview=True,
47
+ show_download_button=False,
48
+ show_share_button=False)
49
+
50
+ iface.launch(inbrowser=True)