-
Notifications
You must be signed in to change notification settings - Fork 10
/
sidebar.py
121 lines (84 loc) · 3.57 KB
/
sidebar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import streamlit as st
import random
from utils.count_files import num_images
class SideBar():
def __init__(self) -> None:
self.num_images = num_images()
self.title = "Ask me anything (AMA)"
self.model_name = None
self.question = None
self.image_idx = None
self._title()
self._model()
self._question()
self._image()
self._show_images()
self._show_author()
def _title(self):
st.sidebar.title(self.title)
def _model(self):
st.sidebar.markdown('## Step 1: Choose model')
self.model_name = st.sidebar.selectbox(
label = 'Please choose the model here',
options = [
'MFB: Multi-modal Factorized Bilinear Pooling with Co-Attention Learning',
# 'MCAN: Deep Modular Co-Attention Networks'
],
index = 0,
key = 'model_name'
)
self._fix_model_name(self.model_name)
def _question(self):
st.sidebar.markdown('## Step 2: Enter question')
self.question = st.sidebar.text_input(
label = 'Please type your question here',
value= 'What is the colour of the hat?',
key= 'question'
)
def _image(self):
st.sidebar.markdown('## Step 3: Choose image')
self.image_idx = st.sidebar.number_input(
label='Please choose the index for the image here (choose -1 to show 6 random images). The model has not been trained on these images.',
min_value=-1, max_value=self.num_images, value=1, step=1,
format='%d'
)
if (self.image_idx == -1):
self.image_idx = None
def _show_images(self):
if self.image_idx is None:
# choose 6 random images
show_idxs = random.sample(list(range(self.num_images)), 6)
for idx in show_idxs:
st.sidebar.image(f'assets/images/{idx}.jpg',use_column_width=True,caption=idx)
else:
st.sidebar.image(f'assets/images/{self.image_idx}.jpg',use_column_width=True,caption=self.image_idx)
def _fix_model_name(self, model_name):
if ('MFB' in model_name):
self.model_name = 'mfb'
elif ('MCAN' in model_name):
self.model_name = 'mcan'
else:
raise NotImplementedError
def _show_author(self):
st.sidebar.markdown(
'## Future releases'
)
st.sidebar.info(
"Version 2 of this is already underway with - \n • custom image uploads \n • many more models! \n "
"To stay tuned for future releases, follow me on Twitter. \n"
"Please consider starring this repo if you like it!"
)
cols = st.sidebar.beta_columns((3,4))
with cols[0]:
st.components.v1.iframe(src="https://ghbtns.com/github-btn.html?user=apugoneappu&repo=ask_me_anything&type=star&count=true&size=large",
height=30)
with cols[1]:
st.components.v1.iframe(src="https://platform.twitter.com/widgets/follow_button.html?screen_name=apoorve_singhal&show_screen_name=true&show_count=false&size=l",
height=30)
st.sidebar.markdown(
'## About me'
)
st.sidebar.info(
"Hi, I'm Apoorve. I like to explain the working of my networks with simple visualisations. \n "
"Please visit [apoorvesinghal.com](https://www.apoorvesinghal.com) if you wish to know more about me."
)