Michele Cafagna commited on
Commit
cd38731
·
1 Parent(s): 4b722d3

added app file and reqs

Browse files
Files changed (2) hide show
  1. app.py +93 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from datasets import load_dataset
3
+
4
+ st.set_page_config(page_title="High-Level dataset")
5
+
6
+ FIELDS = ["scene", "action", "rationale", "object"]
7
+ QS = {
8
+ "scene": "Where is the picture taken?",
9
+ "action": "What is the subject doing?",
10
+ "rationale": "Why is the subject doing it?"
11
+ }
12
+ SPLITS = ["test", "train"]
13
+
14
+ @st.cache
15
+ def load_data(split):
16
+
17
+ #with st.spinner('Loading the data...'):
18
+ dataset = load_dataset("michelecafagna26/hl")
19
+
20
+ coco2id = {int(dataset[split][i]['file_name'].replace("COCO_train2014_", "").replace(".jpg", "")): i for i in
21
+ range(len(dataset[split]))}
22
+
23
+ return dataset, coco2id
24
+
25
+
26
+ def write_obj(dataset, img_id, options, split, list_type="num", show_questions=False,
27
+ show_conf=False):
28
+ st.image(dataset[split][img_id]['image'])
29
+
30
+ # col1, col2 = st.columns(2)
31
+ #
32
+ # col1.metric(label="Diversity score",
33
+ # value=round(self_bleu[f"COCO_train2014_{img_id}.jpg"], 2),
34
+ # delta=round(self_bleu[f"COCO_train2014_{img_id}.jpg"] - AVG_DIVERSITY, 2),
35
+ # help="Normalized complementary 3-way Self-BLEU score. The delta is the difference with the average")
36
+ #
37
+ # col2.metric(label="Purity score",
38
+ # value=round(bleurt[f"COCO_train2014_{img_id}.jpg"], 2),
39
+ # delta=round(bleurt[f"COCO_train2014_{img_id}.jpg"] - AVG_PURITY, 2),
40
+ # help="Normalized 3-way Bleurt score. The delta is the difference with the average")
41
+ #
42
+ for field in options:
43
+
44
+ st.markdown(f"## {field.capitalize()}")
45
+
46
+ if show_questions and field != "object":
47
+ st.markdown(f" Question: _{QS[field]}_")
48
+
49
+ for n, annotation in enumerate(dataset[split][img_id][field]):
50
+
51
+ col1, col2 = st.columns(2)
52
+
53
+ if list_type == "num":
54
+ col1.markdown(f"{n + 1}. {annotation}")
55
+ else:
56
+ col1.markdown(f"{list_type} {annotation}")
57
+
58
+ if show_conf and field != "object":
59
+ col2.metric(label="confidence score",
60
+ value=dataset[split][img_id]['confidence'][field][n])
61
+
62
+
63
+ def main():
64
+
65
+ st.title('High-Level Dataset')
66
+
67
+ show_questions = st.sidebar.checkbox('Questions')
68
+ show_conf = st.sidebar.checkbox('Confidence scores')
69
+ options = st.sidebar.multiselect(
70
+ 'Choose the annotations',
71
+ FIELDS,
72
+ default=FIELDS)
73
+
74
+ split = st.sidebar.selectbox(
75
+ 'Split',
76
+ SPLITS)
77
+
78
+
79
+ dataset, coco2id = load_data(split)
80
+
81
+ # sidebar
82
+ choosen_image = st.selectbox(
83
+ 'Select an image',
84
+ list(coco2id.keys()),
85
+ help="write a key like: 532"
86
+ )
87
+
88
+ write_obj(dataset, coco2id[choosen_image], options=options, split=split,
89
+ list_type="num", show_questions=show_questions, show_conf=show_conf)
90
+
91
+
92
+ if __name__=="__main__":
93
+ main()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ datasets==2.9.0
2
+ streamlit==1.17.0