Spaces:
Sleeping
Sleeping
yolo
Browse files- app/app.py +38 -32
- app/dashboard.ipynb +25 -40
app/app.py
CHANGED
@@ -49,10 +49,22 @@ TEMPORARY_WINE_RECOMMENDATION_FORM_INFO = {}
|
|
49 |
dashboard_layout = html.Div([
|
50 |
# dcc.Link('About this project', href='/wiki'),
|
51 |
html.H1(children='Wineyards around the world', style={'textAlign':'center'}),
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
dcc.Graph(id='world-map-fig'),
|
57 |
|
58 |
|
@@ -61,9 +73,9 @@ dashboard_layout = html.Div([
|
|
61 |
[
|
62 |
html.Div(
|
63 |
[
|
64 |
-
html.
|
65 |
dcc.Dropdown(wine_list, wine_list[0], id='dropdown-selection'),
|
66 |
-
html.
|
67 |
], className='six columns',
|
68 |
),
|
69 |
html.Div(
|
@@ -74,19 +86,19 @@ dashboard_layout = html.Div([
|
|
74 |
], className='row'),
|
75 |
|
76 |
|
77 |
-
html.
|
78 |
html.Div(
|
79 |
[
|
80 |
html.Div(
|
81 |
[
|
82 |
dcc.Dropdown(user_ids, user_ids[0], id='dropdown-selection-user'),
|
83 |
-
html.
|
84 |
], className='six columns',
|
85 |
),
|
86 |
|
87 |
html.Div(
|
88 |
[
|
89 |
-
html.
|
90 |
dash_table.DataTable(
|
91 |
data=raw_ratings.to_dict('records'),
|
92 |
columns=[{'id': c, 'name': c} for c in raw_ratings.columns]
|
@@ -96,13 +108,13 @@ dashboard_layout = html.Div([
|
|
96 |
], className='row'),
|
97 |
|
98 |
|
99 |
-
html.
|
100 |
html.Div(
|
101 |
[
|
102 |
html.Div(
|
103 |
[
|
104 |
#Dropdown for wine name
|
105 |
-
dcc.Dropdown(wine_list, wine_list[0], id='dropdown-selection'),
|
106 |
dcc.Input(id='input-wine-rating', type='number', placeholder='Enter wine rating', min=1, max=5),
|
107 |
], className='six columns',
|
108 |
),
|
@@ -125,17 +137,15 @@ dashboard_layout = html.Div([
|
|
125 |
Input('recommend-wine-from-form-reset', 'n_clicks'),
|
126 |
)
|
127 |
def reset_form(n_clicks):
|
128 |
-
print(n_clicks)
|
129 |
if n_clicks > 0:
|
130 |
TEMPORARY_WINE_RECOMMENDATION_FORM_INFO.clear()
|
131 |
return 0
|
132 |
-
|
133 |
|
134 |
@app.callback(
|
135 |
Output('recommended-wine-rating-info', 'children'),
|
136 |
Output('submit-button', 'n_clicks'),
|
137 |
Input('submit-button', 'n_clicks'),
|
138 |
-
Input('dropdown-selection', 'value'),
|
139 |
Input('input-wine-rating', 'value'),
|
140 |
)
|
141 |
def update_output(n_clicks, wine_name, rating):
|
@@ -164,11 +174,6 @@ def recommend_wine_from_form(n_clicks):
|
|
164 |
return '', 0
|
165 |
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
@app.callback(
|
173 |
Output('dropdown-wr', 'options'),
|
174 |
Input('dropdown-wc', 'value')
|
@@ -220,31 +225,32 @@ def display_page(pathname):
|
|
220 |
return '404'
|
221 |
# You could also return a 404 "URL not found" page here
|
222 |
|
223 |
-
|
224 |
@app.callback(
|
225 |
Output('wine-recommendation', 'children'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
Output('world-map-fig', 'figure'),
|
227 |
Output('wine-recommendation-from-user', 'children'),
|
228 |
-
Input('dropdown-selection', 'value'),
|
229 |
Input('dropdown-wr', 'value'),
|
230 |
Input('dropdown-wc', 'value'),
|
231 |
Input('dropdown-selection-user', 'value')
|
232 |
)
|
233 |
-
def update_graph(
|
234 |
-
### Wine Recommendation ###
|
235 |
-
recommended_wines = None
|
236 |
-
if value:
|
237 |
-
recommended_wines = core.get_top_5_similar_wines(value, wine_similarity_df)[1:]
|
238 |
-
recommended_wines = f"Based on ´{value}´, we recommend: "+"; ".join(recommended_wines)
|
239 |
-
|
240 |
-
|
241 |
## Wine Recommendation from users feedback
|
242 |
|
243 |
wine_recommendation_from_user = core.recommend_wine_from_users(user_rating_df, user_value, 3)
|
244 |
wine_recommendation_from_user = f"Based on user information, we recommend: "+"; ".join(wine_recommendation_from_user)
|
245 |
|
246 |
-
|
247 |
-
|
248 |
### World Map of wineyards ###
|
249 |
|
250 |
geo_df = pd.read_csv('data/processed_wineyards.csv')
|
@@ -274,7 +280,7 @@ def update_graph(value,wr,wc, user_value):
|
|
274 |
|
275 |
|
276 |
|
277 |
-
return
|
278 |
|
279 |
|
280 |
if __name__ == "__main__":
|
|
|
49 |
dashboard_layout = html.Div([
|
50 |
# dcc.Link('About this project', href='/wiki'),
|
51 |
html.H1(children='Wineyards around the world', style={'textAlign':'center'}),
|
52 |
+
|
53 |
+
html.Div(
|
54 |
+
[
|
55 |
+
html.Div(
|
56 |
+
[
|
57 |
+
html.H4(children='Country', style={'textAlign':'center'}),
|
58 |
+
dcc.Dropdown(wine_country, wine_country[-1], id='dropdown-wc'),
|
59 |
+
], className='six columns',
|
60 |
+
),
|
61 |
+
html.Div(
|
62 |
+
[
|
63 |
+
html.H4(children='Region', style={'textAlign':'center'}),
|
64 |
+
dcc.Dropdown(['all'],'all', id='dropdown-wr'),
|
65 |
+
], className='six columns',
|
66 |
+
)
|
67 |
+
], className='row'),
|
68 |
dcc.Graph(id='world-map-fig'),
|
69 |
|
70 |
|
|
|
73 |
[
|
74 |
html.Div(
|
75 |
[
|
76 |
+
html.H4(children='Wine Recommender', style={'textAlign':'center'}),
|
77 |
dcc.Dropdown(wine_list, wine_list[0], id='dropdown-selection'),
|
78 |
+
html.P(id='wine-recommendation', style={'textAlign':'center'}),
|
79 |
], className='six columns',
|
80 |
),
|
81 |
html.Div(
|
|
|
86 |
], className='row'),
|
87 |
|
88 |
|
89 |
+
html.H4(children="Wine Recommender based on users' feedback", style={'textAlign':'center'}),
|
90 |
html.Div(
|
91 |
[
|
92 |
html.Div(
|
93 |
[
|
94 |
dcc.Dropdown(user_ids, user_ids[0], id='dropdown-selection-user'),
|
95 |
+
html.P(id='wine-recommendation-from-user', style={'textAlign':'center'}),
|
96 |
], className='six columns',
|
97 |
),
|
98 |
|
99 |
html.Div(
|
100 |
[
|
101 |
+
html.P(children='Data Example', style={'textAlign':'left'}),
|
102 |
dash_table.DataTable(
|
103 |
data=raw_ratings.to_dict('records'),
|
104 |
columns=[{'id': c, 'name': c} for c in raw_ratings.columns]
|
|
|
108 |
], className='row'),
|
109 |
|
110 |
|
111 |
+
html.H4(children="Wine Preferences Form", style={'textAlign':'center'}),
|
112 |
html.Div(
|
113 |
[
|
114 |
html.Div(
|
115 |
[
|
116 |
#Dropdown for wine name
|
117 |
+
dcc.Dropdown(wine_list, wine_list[0], id='dropdown-selection-wine-form'),
|
118 |
dcc.Input(id='input-wine-rating', type='number', placeholder='Enter wine rating', min=1, max=5),
|
119 |
], className='six columns',
|
120 |
),
|
|
|
137 |
Input('recommend-wine-from-form-reset', 'n_clicks'),
|
138 |
)
|
139 |
def reset_form(n_clicks):
|
|
|
140 |
if n_clicks > 0:
|
141 |
TEMPORARY_WINE_RECOMMENDATION_FORM_INFO.clear()
|
142 |
return 0
|
|
|
143 |
|
144 |
@app.callback(
|
145 |
Output('recommended-wine-rating-info', 'children'),
|
146 |
Output('submit-button', 'n_clicks'),
|
147 |
Input('submit-button', 'n_clicks'),
|
148 |
+
Input('dropdown-selection-wine-form', 'value'),
|
149 |
Input('input-wine-rating', 'value'),
|
150 |
)
|
151 |
def update_output(n_clicks, wine_name, rating):
|
|
|
174 |
return '', 0
|
175 |
|
176 |
|
|
|
|
|
|
|
|
|
|
|
177 |
@app.callback(
|
178 |
Output('dropdown-wr', 'options'),
|
179 |
Input('dropdown-wc', 'value')
|
|
|
225 |
return '404'
|
226 |
# You could also return a 404 "URL not found" page here
|
227 |
|
|
|
228 |
@app.callback(
|
229 |
Output('wine-recommendation', 'children'),
|
230 |
+
Input('dropdown-selection', 'value')
|
231 |
+
)
|
232 |
+
def update_recommendation(value):
|
233 |
+
if value:
|
234 |
+
recommended_wines = core.get_top_5_similar_wines(value, wine_similarity_df)[1:]
|
235 |
+
return f"Based on ´{value}´, we recommend: "+"; ".join(recommended_wines)
|
236 |
+
return ''
|
237 |
+
|
238 |
+
|
239 |
+
|
240 |
+
|
241 |
+
@app.callback(
|
242 |
Output('world-map-fig', 'figure'),
|
243 |
Output('wine-recommendation-from-user', 'children'),
|
|
|
244 |
Input('dropdown-wr', 'value'),
|
245 |
Input('dropdown-wc', 'value'),
|
246 |
Input('dropdown-selection-user', 'value')
|
247 |
)
|
248 |
+
def update_graph(wr,wc, user_value):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
## Wine Recommendation from users feedback
|
250 |
|
251 |
wine_recommendation_from_user = core.recommend_wine_from_users(user_rating_df, user_value, 3)
|
252 |
wine_recommendation_from_user = f"Based on user information, we recommend: "+"; ".join(wine_recommendation_from_user)
|
253 |
|
|
|
|
|
254 |
### World Map of wineyards ###
|
255 |
|
256 |
geo_df = pd.read_csv('data/processed_wineyards.csv')
|
|
|
280 |
|
281 |
|
282 |
|
283 |
+
return world_map_fig, wine_recommendation_from_user
|
284 |
|
285 |
|
286 |
if __name__ == "__main__":
|
app/dashboard.ipynb
CHANGED
@@ -2,14 +2,14 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
9 |
"name": "stderr",
|
10 |
"output_type": "stream",
|
11 |
"text": [
|
12 |
-
"/var/folders/b4/lwfgccm95kqd2skcwvrt2fr00000gn/T/ipykernel_36332/
|
13 |
"\n",
|
14 |
"Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
|
15 |
"\n"
|
@@ -30,7 +30,7 @@
|
|
30 |
" "
|
31 |
],
|
32 |
"text/plain": [
|
33 |
-
"<IPython.lib.display.IFrame at
|
34 |
]
|
35 |
},
|
36 |
"metadata": {},
|
@@ -48,33 +48,6 @@
|
|
48 |
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
49 |
"\n"
|
50 |
]
|
51 |
-
},
|
52 |
-
{
|
53 |
-
"name": "stdout",
|
54 |
-
"output_type": "stream",
|
55 |
-
"text": [
|
56 |
-
"Sup Azevedo\n"
|
57 |
-
]
|
58 |
-
},
|
59 |
-
{
|
60 |
-
"name": "stderr",
|
61 |
-
"output_type": "stream",
|
62 |
-
"text": [
|
63 |
-
"/Users/ruimelo/Documents/GitHub/eda/app/core.py:21: SettingWithCopyWarning:\n",
|
64 |
-
"\n",
|
65 |
-
"\n",
|
66 |
-
"A value is trying to be set on a copy of a slice from a DataFrame\n",
|
67 |
-
"\n",
|
68 |
-
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
69 |
-
"\n"
|
70 |
-
]
|
71 |
-
},
|
72 |
-
{
|
73 |
-
"name": "stdout",
|
74 |
-
"output_type": "stream",
|
75 |
-
"text": [
|
76 |
-
"Sup Aura\n"
|
77 |
-
]
|
78 |
}
|
79 |
],
|
80 |
"source": [
|
@@ -129,10 +102,22 @@
|
|
129 |
"dashboard_layout = html.Div([\n",
|
130 |
" # dcc.Link('About this project', href='/wiki'),\n",
|
131 |
" html.H1(children='Wineyards around the world', style={'textAlign':'center'}),\n",
|
132 |
-
"
|
133 |
-
"
|
134 |
-
"
|
135 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
" dcc.Graph(id='world-map-fig'),\n",
|
137 |
"\n",
|
138 |
" \n",
|
@@ -141,9 +126,9 @@
|
|
141 |
" [\n",
|
142 |
" html.Div(\n",
|
143 |
" [\n",
|
144 |
-
" html.
|
145 |
" dcc.Dropdown(wine_list, wine_list[0], id='dropdown-selection'),\n",
|
146 |
-
" html.
|
147 |
" ], className='six columns',\n",
|
148 |
" ),\n",
|
149 |
" html.Div(\n",
|
@@ -154,19 +139,19 @@
|
|
154 |
" ], className='row'),\n",
|
155 |
" \n",
|
156 |
" \n",
|
157 |
-
" html.
|
158 |
" html.Div(\n",
|
159 |
" [\n",
|
160 |
" html.Div(\n",
|
161 |
" [\n",
|
162 |
" dcc.Dropdown(user_ids, user_ids[0], id='dropdown-selection-user'),\n",
|
163 |
-
" html.
|
164 |
" ], className='six columns',\n",
|
165 |
" ),\n",
|
166 |
" \n",
|
167 |
" html.Div(\n",
|
168 |
" [ \n",
|
169 |
-
" html.
|
170 |
" dash_table.DataTable(\n",
|
171 |
" data=raw_ratings.to_dict('records'),\n",
|
172 |
" columns=[{'id': c, 'name': c} for c in raw_ratings.columns]\n",
|
@@ -176,7 +161,7 @@
|
|
176 |
" ], className='row'),\n",
|
177 |
" \n",
|
178 |
" \n",
|
179 |
-
" html.
|
180 |
" html.Div(\n",
|
181 |
" [\n",
|
182 |
" html.Div(\n",
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 12,
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
9 |
"name": "stderr",
|
10 |
"output_type": "stream",
|
11 |
"text": [
|
12 |
+
"/var/folders/b4/lwfgccm95kqd2skcwvrt2fr00000gn/T/ipykernel_36332/1794122908.py:94: FutureWarning:\n",
|
13 |
"\n",
|
14 |
"Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
|
15 |
"\n"
|
|
|
30 |
" "
|
31 |
],
|
32 |
"text/plain": [
|
33 |
+
"<IPython.lib.display.IFrame at 0x2ae513e50>"
|
34 |
]
|
35 |
},
|
36 |
"metadata": {},
|
|
|
48 |
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
49 |
"\n"
|
50 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
],
|
53 |
"source": [
|
|
|
102 |
"dashboard_layout = html.Div([\n",
|
103 |
" # dcc.Link('About this project', href='/wiki'),\n",
|
104 |
" html.H1(children='Wineyards around the world', style={'textAlign':'center'}),\n",
|
105 |
+
" \n",
|
106 |
+
" html.Div(\n",
|
107 |
+
" [\n",
|
108 |
+
" html.Div(\n",
|
109 |
+
" [\n",
|
110 |
+
" html.H4(children='Country', style={'textAlign':'center'}),\n",
|
111 |
+
" dcc.Dropdown(wine_country, wine_country[-1], id='dropdown-wc'),\n",
|
112 |
+
" ], className='six columns',\n",
|
113 |
+
" ),\n",
|
114 |
+
" html.Div(\n",
|
115 |
+
" [\n",
|
116 |
+
" html.H4(children='Region', style={'textAlign':'center'}),\n",
|
117 |
+
" dcc.Dropdown(['all'],'all', id='dropdown-wr'),\n",
|
118 |
+
" ], className='six columns',\n",
|
119 |
+
" )\n",
|
120 |
+
" ], className='row'),\n",
|
121 |
" dcc.Graph(id='world-map-fig'),\n",
|
122 |
"\n",
|
123 |
" \n",
|
|
|
126 |
" [\n",
|
127 |
" html.Div(\n",
|
128 |
" [\n",
|
129 |
+
" html.H4(children='Wine Recommender', style={'textAlign':'center'}),\n",
|
130 |
" dcc.Dropdown(wine_list, wine_list[0], id='dropdown-selection'),\n",
|
131 |
+
" html.P(id='wine-recommendation', style={'textAlign':'center'}),\n",
|
132 |
" ], className='six columns',\n",
|
133 |
" ),\n",
|
134 |
" html.Div(\n",
|
|
|
139 |
" ], className='row'),\n",
|
140 |
" \n",
|
141 |
" \n",
|
142 |
+
" html.H4(children=\"Wine Recommender based on users' feedback\", style={'textAlign':'center'}),\n",
|
143 |
" html.Div(\n",
|
144 |
" [\n",
|
145 |
" html.Div(\n",
|
146 |
" [\n",
|
147 |
" dcc.Dropdown(user_ids, user_ids[0], id='dropdown-selection-user'),\n",
|
148 |
+
" html.P(id='wine-recommendation-from-user', style={'textAlign':'center'}),\n",
|
149 |
" ], className='six columns',\n",
|
150 |
" ),\n",
|
151 |
" \n",
|
152 |
" html.Div(\n",
|
153 |
" [ \n",
|
154 |
+
" html.P(children='Data Example', style={'textAlign':'left'}),\n",
|
155 |
" dash_table.DataTable(\n",
|
156 |
" data=raw_ratings.to_dict('records'),\n",
|
157 |
" columns=[{'id': c, 'name': c} for c in raw_ratings.columns]\n",
|
|
|
161 |
" ], className='row'),\n",
|
162 |
" \n",
|
163 |
" \n",
|
164 |
+
" html.H4(children=\"Wine Preferences Form\", style={'textAlign':'center'}),\n",
|
165 |
" html.Div(\n",
|
166 |
" [\n",
|
167 |
" html.Div(\n",
|