-
Notifications
You must be signed in to change notification settings - Fork 1
/
view.py
234 lines (219 loc) · 8.29 KB
/
view.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# Importing modules
import dash_html_components as html
import dash_bootstrap_components as dbc
import dash_core_components as dcc
'''
MAIN LAYOUTS
'''
# Navbar layout
def navbar():
navbar = dbc.Navbar(
[
dbc.NavbarBrand(
[
html.H5(html.I(className="fas fa-cannabis")),
html.H5("CannaRec")
]
),
dbc.Collapse(
[
html.Ul(
[
dbc.NavItem(html.A("Home", href = '#home', className = "nav-link")),
dbc.NavItem(html.A("Search By Strain", href = '#by-strain', className = "nav-link")),
dbc.NavItem(html.A("Search By Preference", href = '#by-flavfeel', className = "nav-link")),
dbc.NavItem(html.A("Contact", href = 'https://www.linkedin.com/in/dylan-mendonca-65165898/', className = "nav-link"))
], className = "nav navbar-nav ml-auto"
)
], className = "navbar-collapse"),
], fixed = 'top', className = "main-navbar bg-transparent", light=False,
)
return navbar
# Home Page Layout
def jumbotron():
jumbotron = html.Div(
[
html.Div(),
dbc.Jumbotron(
[
html.H1("CannaRec", className="display-3"),
html.P(
["Picking a new strain can be hard.",
html.Br(),
"We're here to help."],
className="lead",
),
html.Hr(className="my-2"),
html.P(
"Click one of the options below to get started."
),
html.Div(
[
dbc.Button(html.A("Search By Strain", href = "#by-strain", className = "white_link"), color="primary",),
dbc.Button(html.A("Search By Preference", href = "#by-flavfeel", className = "white_link"), color="primary",style = {'margin-left':'15px'})
], className = "jumbo-buttons"),
],
),
html.Div()
], className = "landing", id = "home"
)
return jumbotron
# Search By Strain Page Layout
def by_strain(strain_dropdown):
body = html.Div(
[
html.Div(),
dbc.Jumbotron(
[
html.Div(
[
html.H4("Search By Strain"),
html.H6("What strain do you like?"),
dcc.Dropdown(
id = "strain_name",
options = strain_dropdown.to_dict(orient='records'),
value = None,
placeholder = "Select a Strain"
),
html.Br(),
html.H6("Why do you like this strain?"),
dcc.Dropdown(
id = "why_strain",
options = [
{'label':"Feels Great", "value":"general"},
{'label':"Tastes Amazing", "value":"flavors"},
{'label':"Treats a Medical Condition", "value":"medical"},
],
value = None,
placeholder = "Select the Reason"
),
html.Br(),
dbc.Button("CannaRec Me!", id = "letsgo", color = "primary")
], className = "question-section"
),
],
),
html.Div(),
html.Div(
[
dcc.Loading(
[
html.Div(
[
], id = "results", className = "results"
)
]
)
]
),
html.Div()
], id = "by-strain"
)
return body
# Search By Flavors and Feelings Layout
def by_flavfeels(general_dropdown, flavor_dropdown, medical_dropdown):
body2 = html.Div(
[
html.Div(),
dbc.Jumbotron(
[
html.Div(
[
html.H4("Search By Preference"),
html.H6("What feelings do you like?"),
dcc.Dropdown(
id = "feelings_drop",
options = general_dropdown.to_dict(orient='records'),
value = None,
placeholder = "Select Feelings",
multi = True
),
html.Br(),
html.H6("What flavors do you like?"),
dcc.Dropdown(
id = "flavors_drop",
options = flavor_dropdown.to_dict(orient='records'),
value = None,
placeholder = "Select Flavors",
multi = True
),
html.Br(),
html.H6("What medical conditions do you want to treat?"),
dcc.Dropdown(
id = "medical_drop",
options = medical_dropdown.to_dict(orient='records'),
value = None,
placeholder = "Select Medical Condition to Treat",
multi = True
),
html.Br(),
dbc.Button("CannaRec Me!", id = "letsgo2", color = "primary")
], className = "question-section"
)
],
),
html.Div(),
html.Div(
[
dcc.Loading(
[
html.Div(
[
], id = "results2", className = "results"
)
]
)
]
),
html.Div()
], id = "by-flavfeel"
)
return body2
'''
HELPER FUNCTIONS
'''
# Creates a little rectangular shaped card for a strain with all info
def create_cannacard(strain_name, strain_type, strain_symbol, strain_url, similarity):
if similarity > 0.90:
sim = "high"
elif similarity > 0.70:
sim = "med"
else:
sim = "low"
div = html.Div(
[
html.Div(
[
strain_type.title()
], className = "strain-header",
),
html.Div(
[
"%d%% Match" % (similarity*100)
], className = f"strain-similarity {sim}",
),
html.Div(
[
strain_symbol.title()
], className = "strain-symbol",
),
html.Div(
[
strain_name
], className = "strain-name",
),
], className = f"strain-card {strain_type.lower()}"
)
return html.A([div], href = strain_url, className = "strain-l")
# Create arrow at bottom right on scroll
def create_arrow():
div = html.Div(
[
html.Span(
[
html.A(html.I(className = "fa fa-3x fa-arrow-circle-up"), href = "#home")
], className = "scroll-top-inner"
)
], className = "scroll-top-wrapper"
)
return div