rufimelo commited on
Commit
5a9e05e
·
1 Parent(s): bd7b6e0
Files changed (1) hide show
  1. app/dashboard.ipynb +24 -78
app/dashboard.ipynb CHANGED
@@ -2,14 +2,14 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": null,
6
  "metadata": {},
7
  "outputs": [
8
  {
9
  "name": "stderr",
10
  "output_type": "stream",
11
  "text": [
12
- "/var/folders/b4/lwfgccm95kqd2skcwvrt2fr00000gn/T/ipykernel_23769/1782084106.py:82: 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,7 +30,7 @@
30
  " "
31
  ],
32
  "text/plain": [
33
- "<IPython.lib.display.IFrame at 0x2a978bdf0>"
34
  ]
35
  },
36
  "metadata": {},
@@ -40,7 +40,7 @@
40
  "name": "stderr",
41
  "output_type": "stream",
42
  "text": [
43
- "/Users/ruimelo/Documents/GitHub/eda/app/core.py:20: SettingWithCopyWarning:\n",
44
  "\n",
45
  "\n",
46
  "A value is trying to be set on a copy of a slice from a DataFrame\n",
@@ -53,75 +53,27 @@
53
  "name": "stdout",
54
  "output_type": "stream",
55
  "text": [
56
- "0\n"
57
  ]
58
  },
59
  {
60
  "name": "stderr",
61
  "output_type": "stream",
62
  "text": [
63
- "/Users/ruimelo/Documents/GitHub/eda/app/core.py:20: 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
- "/Users/ruimelo/Documents/GitHub/eda/app/core.py:31: SettingWithCopyWarning:\n",
71
  "\n",
72
  "\n",
73
  "A value is trying to be set on a copy of a slice from a DataFrame\n",
74
  "\n",
75
  "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
76
- "\n",
77
- "[2024-09-17 19:32:00,521] ERROR in app: Exception on /_dash-update-component [POST]\n",
78
- "Traceback (most recent call last):\n",
79
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/flask/app.py\", line 1473, in wsgi_app\n",
80
- " response = self.full_dispatch_request()\n",
81
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/flask/app.py\", line 882, in full_dispatch_request\n",
82
- " rv = self.handle_user_exception(e)\n",
83
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/flask/app.py\", line 880, in full_dispatch_request\n",
84
- " rv = self.dispatch_request()\n",
85
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/flask/app.py\", line 865, in dispatch_request\n",
86
- " return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]\n",
87
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/dash/dash.py\", line 1376, in dispatch\n",
88
- " ctx.run(\n",
89
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/dash/_callback.py\", line 514, in add_context\n",
90
- " raise err\n",
91
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/dash/_callback.py\", line 503, in add_context\n",
92
- " output_value = _invoke_callback(func, *func_args, **func_kwargs)\n",
93
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/dash/_callback.py\", line 43, in _invoke_callback\n",
94
- " return func(*args, **kwargs) # %% callback invoked %%\n",
95
- " File \"/var/folders/b4/lwfgccm95kqd2skcwvrt2fr00000gn/T/ipykernel_23769/1782084106.py\", line 158, in recommend_wine_from_form\n",
96
- " user_rating_df['cluster'] = core.get_most_similar_user_clust(user_rating_df, user)\n",
97
- " File \"/Users/ruimelo/Documents/GitHub/eda/app/core.py\", line 34, in get_most_similar_user_clust\n",
98
- " cluster_avg = cluster_avg[new_user_ratings.index]\n",
99
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/pandas/core/series.py\", line 1153, in __getitem__\n",
100
- " return self._get_with(key)\n",
101
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/pandas/core/series.py\", line 1194, in _get_with\n",
102
- " return self.loc[key]\n",
103
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/pandas/core/indexing.py\", line 1191, in __getitem__\n",
104
- " return self._getitem_axis(maybe_callable, axis=axis)\n",
105
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/pandas/core/indexing.py\", line 1420, in _getitem_axis\n",
106
- " return self._getitem_iterable(key, axis=axis)\n",
107
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/pandas/core/indexing.py\", line 1360, in _getitem_iterable\n",
108
- " keyarr, indexer = self._get_listlike_indexer(key, axis)\n",
109
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/pandas/core/indexing.py\", line 1558, in _get_listlike_indexer\n",
110
- " keyarr, indexer = ax._get_indexer_strict(key, axis_name)\n",
111
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/pandas/core/indexes/base.py\", line 6200, in _get_indexer_strict\n",
112
- " self._raise_if_missing(keyarr, indexer, axis_name)\n",
113
- " File \"/Users/ruimelo/anaconda3/envs/gan-nlp/lib/python3.10/site-packages/pandas/core/indexes/base.py\", line 6252, in _raise_if_missing\n",
114
- " raise KeyError(f\"{not_found} not in index\")\n",
115
- "KeyError: \"['user'] not in index\"\n"
116
  ]
117
  },
118
  {
119
  "name": "stdout",
120
  "output_type": "stream",
121
  "text": [
122
- "Dedicado 2.0\n",
123
- "user temporary_user\n",
124
- "Name: temporary_user, dtype: object\n"
125
  ]
126
  }
127
  ],
@@ -230,7 +182,7 @@
230
  " html.Div(\n",
231
  " [\n",
232
  " #Dropdown for wine name\n",
233
- " dcc.Dropdown(wine_list, wine_list[0], id='dropdown-selection'),\n",
234
  " dcc.Input(id='input-wine-rating', type='number', placeholder='Enter wine rating', min=1, max=5),\n",
235
  " ], className='six columns',\n",
236
  " ),\n",
@@ -253,17 +205,15 @@
253
  " Input('recommend-wine-from-form-reset', 'n_clicks'),\n",
254
  ")\n",
255
  "def reset_form(n_clicks):\n",
256
- " print(n_clicks)\n",
257
  " if n_clicks > 0:\n",
258
  " TEMPORARY_WINE_RECOMMENDATION_FORM_INFO.clear()\n",
259
  " return 0\n",
260
- " \n",
261
  "\n",
262
  "@app.callback(\n",
263
  " Output('recommended-wine-rating-info', 'children'),\n",
264
  " Output('submit-button', 'n_clicks'),\n",
265
  " Input('submit-button', 'n_clicks'),\n",
266
- " Input('dropdown-selection', 'value'),\n",
267
  " Input('input-wine-rating', 'value'),\n",
268
  ")\n",
269
  "def update_output(n_clicks, wine_name, rating):\n",
@@ -292,11 +242,6 @@
292
  " return '', 0\n",
293
  "\n",
294
  "\n",
295
- "\n",
296
- "\n",
297
- "\n",
298
- "\n",
299
- "\n",
300
  "@app.callback(\n",
301
  " Output('dropdown-wr', 'options'),\n",
302
  " Input('dropdown-wc', 'value')\n",
@@ -348,31 +293,32 @@
348
  " return '404'\n",
349
  " # You could also return a 404 \"URL not found\" page here\n",
350
  "\n",
351
- "\n",
352
  "@app.callback(\n",
353
  " Output('wine-recommendation', 'children'),\n",
 
 
 
 
 
 
 
 
 
 
 
 
354
  " Output('world-map-fig', 'figure'),\n",
355
  " Output('wine-recommendation-from-user', 'children'),\n",
356
- " Input('dropdown-selection', 'value'),\n",
357
  " Input('dropdown-wr', 'value'),\n",
358
  " Input('dropdown-wc', 'value'),\n",
359
  " Input('dropdown-selection-user', 'value')\n",
360
  ")\n",
361
- "def update_graph(value,wr,wc, user_value):\n",
362
- " ### Wine Recommendation ###\n",
363
- " recommended_wines = None\n",
364
- " if value:\n",
365
- " recommended_wines = core.get_top_5_similar_wines(value, wine_similarity_df)[1:]\n",
366
- " recommended_wines = f\"Based on ´{value}´, we recommend: \"+\"; \".join(recommended_wines)\n",
367
- "\n",
368
- "\n",
369
  " ## Wine Recommendation from users feedback\n",
370
  "\n",
371
  " wine_recommendation_from_user = core.recommend_wine_from_users(user_rating_df, user_value, 3)\n",
372
  " wine_recommendation_from_user = f\"Based on user information, we recommend: \"+\"; \".join(wine_recommendation_from_user)\n",
373
  "\n",
374
- "\n",
375
- "\n",
376
  " ### World Map of wineyards ###\n",
377
  "\n",
378
  " geo_df = pd.read_csv('data/processed_wineyards.csv')\n",
@@ -402,7 +348,7 @@
402
  " \n",
403
  "\n",
404
  "\n",
405
- " return recommended_wines, world_map_fig, wine_recommendation_from_user\n",
406
  "\n",
407
  "\n",
408
  "if __name__ == \"__main__\":\n",
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 9,
6
  "metadata": {},
7
  "outputs": [
8
  {
9
  "name": "stderr",
10
  "output_type": "stream",
11
  "text": [
12
+ "/var/folders/b4/lwfgccm95kqd2skcwvrt2fr00000gn/T/ipykernel_36332/1038910995.py:82: 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 0x2ad7f79a0>"
34
  ]
35
  },
36
  "metadata": {},
 
40
  "name": "stderr",
41
  "output_type": "stream",
42
  "text": [
43
+ "/Users/ruimelo/Documents/GitHub/eda/app/core.py:21: SettingWithCopyWarning:\n",
44
  "\n",
45
  "\n",
46
  "A value is trying to be set on a copy of a slice from a DataFrame\n",
 
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
  ],
 
182
  " html.Div(\n",
183
  " [\n",
184
  " #Dropdown for wine name\n",
185
+ " dcc.Dropdown(wine_list, wine_list[0], id='dropdown-selection-wine-form'),\n",
186
  " dcc.Input(id='input-wine-rating', type='number', placeholder='Enter wine rating', min=1, max=5),\n",
187
  " ], className='six columns',\n",
188
  " ),\n",
 
205
  " Input('recommend-wine-from-form-reset', 'n_clicks'),\n",
206
  ")\n",
207
  "def reset_form(n_clicks):\n",
 
208
  " if n_clicks > 0:\n",
209
  " TEMPORARY_WINE_RECOMMENDATION_FORM_INFO.clear()\n",
210
  " return 0\n",
 
211
  "\n",
212
  "@app.callback(\n",
213
  " Output('recommended-wine-rating-info', 'children'),\n",
214
  " Output('submit-button', 'n_clicks'),\n",
215
  " Input('submit-button', 'n_clicks'),\n",
216
+ " Input('dropdown-selection-wine-form', 'value'),\n",
217
  " Input('input-wine-rating', 'value'),\n",
218
  ")\n",
219
  "def update_output(n_clicks, wine_name, rating):\n",
 
242
  " return '', 0\n",
243
  "\n",
244
  "\n",
 
 
 
 
 
245
  "@app.callback(\n",
246
  " Output('dropdown-wr', 'options'),\n",
247
  " Input('dropdown-wc', 'value')\n",
 
293
  " return '404'\n",
294
  " # You could also return a 404 \"URL not found\" page here\n",
295
  "\n",
 
296
  "@app.callback(\n",
297
  " Output('wine-recommendation', 'children'),\n",
298
+ " Input('dropdown-selection', 'value')\n",
299
+ ")\n",
300
+ "def update_recommendation(value):\n",
301
+ " if value:\n",
302
+ " recommended_wines = core.get_top_5_similar_wines(value, wine_similarity_df)[1:]\n",
303
+ " return f\"Based on ´{value}´, we recommend: \"+\"; \".join(recommended_wines)\n",
304
+ " return ''\n",
305
+ "\n",
306
+ "\n",
307
+ "\n",
308
+ "\n",
309
+ "@app.callback(\n",
310
  " Output('world-map-fig', 'figure'),\n",
311
  " Output('wine-recommendation-from-user', 'children'),\n",
 
312
  " Input('dropdown-wr', 'value'),\n",
313
  " Input('dropdown-wc', 'value'),\n",
314
  " Input('dropdown-selection-user', 'value')\n",
315
  ")\n",
316
+ "def update_graph(wr,wc, user_value):\n",
 
 
 
 
 
 
 
317
  " ## Wine Recommendation from users feedback\n",
318
  "\n",
319
  " wine_recommendation_from_user = core.recommend_wine_from_users(user_rating_df, user_value, 3)\n",
320
  " wine_recommendation_from_user = f\"Based on user information, we recommend: \"+\"; \".join(wine_recommendation_from_user)\n",
321
  "\n",
 
 
322
  " ### World Map of wineyards ###\n",
323
  "\n",
324
  " geo_df = pd.read_csv('data/processed_wineyards.csv')\n",
 
348
  " \n",
349
  "\n",
350
  "\n",
351
+ " return world_map_fig, wine_recommendation_from_user\n",
352
  "\n",
353
  "\n",
354
  "if __name__ == \"__main__\":\n",