rufimelo commited on
Commit
26485d2
·
1 Parent(s): 823be8e
Files changed (2) hide show
  1. app/app.py +9 -14
  2. app/dashboard.ipynb +19 -17
app/app.py CHANGED
@@ -118,27 +118,22 @@ dashboard_layout = html.Div([
118
  # Button to submit the form
119
  html.Button('Recommend Wine', id='recommend-wine-from-form', n_clicks=0),
120
  html.Div(id='recommended-wine-form-output', style={'textAlign':'center'}),
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
  ], style={'background-color': '#333', 'font-family': 'Fantasy', 'color': '#999', 'padding': '10px'})
129
 
130
-
131
  @app.callback(
 
132
  Input('recommend-wine-from-form-reset', 'n_clicks'),
133
  )
134
  def reset_form(n_clicks):
 
135
  if n_clicks > 0:
136
  TEMPORARY_WINE_RECOMMENDATION_FORM_INFO.clear()
137
- return
138
 
139
 
140
  @app.callback(
141
  Output('recommended-wine-rating-info', 'children'),
 
142
  Input('submit-button', 'n_clicks'),
143
  Input('dropdown-selection', 'value'),
144
  Input('input-wine-rating', 'value'),
@@ -146,12 +141,12 @@ def reset_form(n_clicks):
146
  def update_output(n_clicks, wine_name, rating):
147
  if n_clicks > 0:
148
  TEMPORARY_WINE_RECOMMENDATION_FORM_INFO[wine_name] = rating
149
- n_clicks = 0
150
- return f'You rated {wine_name} with a score of {rating}'
151
- return ''
152
 
153
  @app.callback(
154
  Output('recommended-wine-form-output', 'children'),
 
155
  Input('recommend-wine-from-form', 'n_clicks'),
156
  )
157
  def recommend_wine_from_form(n_clicks):
@@ -164,8 +159,8 @@ def recommend_wine_from_form(n_clicks):
164
 
165
  wine_recommendation_from_user = core.recommend_wine_from_users(user_rating_df, user, 3)
166
  wine_recommendation_from_user = f"Based on user form, we recommend: "+"; ".join(wine_recommendation_from_user)
167
- return wine_recommendation_from_user
168
- return ''
169
 
170
 
171
 
 
118
  # Button to submit the form
119
  html.Button('Recommend Wine', id='recommend-wine-from-form', n_clicks=0),
120
  html.Div(id='recommended-wine-form-output', style={'textAlign':'center'}),
 
 
 
 
 
 
 
121
  ], style={'background-color': '#333', 'font-family': 'Fantasy', 'color': '#999', 'padding': '10px'})
122
 
 
123
  @app.callback(
124
+ Output('recommend-wine-from-form-reset', 'n_clicks'),
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'),
 
141
  def update_output(n_clicks, wine_name, rating):
142
  if n_clicks > 0:
143
  TEMPORARY_WINE_RECOMMENDATION_FORM_INFO[wine_name] = rating
144
+ return f'You rated {wine_name} with a score of {rating}', 0
145
+ return '', 0
 
146
 
147
  @app.callback(
148
  Output('recommended-wine-form-output', 'children'),
149
+ Output('recommend-wine-from-form', 'n_clicks'),
150
  Input('recommend-wine-from-form', 'n_clicks'),
151
  )
152
  def recommend_wine_from_form(n_clicks):
 
159
 
160
  wine_recommendation_from_user = core.recommend_wine_from_users(user_rating_df, user, 3)
161
  wine_recommendation_from_user = f"Based on user form, we recommend: "+"; ".join(wine_recommendation_from_user)
162
+ return wine_recommendation_from_user, 0
163
+ return '', 0
164
 
165
 
166
 
app/dashboard.ipynb CHANGED
@@ -2,14 +2,14 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 5,
6
  "metadata": {},
7
  "outputs": [
8
  {
9
  "name": "stderr",
10
  "output_type": "stream",
11
  "text": [
12
- "/var/folders/b4/lwfgccm95kqd2skcwvrt2fr00000gn/T/ipykernel_4768/1094357399.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 0x2b1675fc0>"
34
  ]
35
  },
36
  "metadata": {},
@@ -48,6 +48,13 @@
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": [
@@ -171,27 +178,22 @@
171
  " # Button to submit the form\n",
172
  " html.Button('Recommend Wine', id='recommend-wine-from-form', n_clicks=0),\n",
173
  " html.Div(id='recommended-wine-form-output', style={'textAlign':'center'}),\n",
174
- "\n",
175
- "\n",
176
- "\n",
177
- " \n",
178
- "\n",
179
- " \n",
180
- "\n",
181
  "], style={'background-color': '#333', 'font-family': 'Fantasy', 'color': '#999', 'padding': '10px'})\n",
182
  "\n",
183
- "\n",
184
  "@app.callback(\n",
 
185
  " Input('recommend-wine-from-form-reset', 'n_clicks'),\n",
186
  ")\n",
187
  "def reset_form(n_clicks):\n",
 
188
  " if n_clicks > 0:\n",
189
  " TEMPORARY_WINE_RECOMMENDATION_FORM_INFO.clear()\n",
190
- " return\n",
191
  " \n",
192
  "\n",
193
  "@app.callback(\n",
194
  " Output('recommended-wine-rating-info', 'children'),\n",
 
195
  " Input('submit-button', 'n_clicks'),\n",
196
  " Input('dropdown-selection', 'value'),\n",
197
  " Input('input-wine-rating', 'value'),\n",
@@ -199,12 +201,12 @@
199
  "def update_output(n_clicks, wine_name, rating):\n",
200
  " if n_clicks > 0:\n",
201
  " TEMPORARY_WINE_RECOMMENDATION_FORM_INFO[wine_name] = rating\n",
202
- " n_clicks = 0\n",
203
- " return f'You rated {wine_name} with a score of {rating}'\n",
204
- " return ''\n",
205
  "\n",
206
  "@app.callback(\n",
207
  " Output('recommended-wine-form-output', 'children'),\n",
 
208
  " Input('recommend-wine-from-form', 'n_clicks'),\n",
209
  ")\n",
210
  "def recommend_wine_from_form(n_clicks):\n",
@@ -217,8 +219,8 @@
217
  "\n",
218
  " wine_recommendation_from_user = core.recommend_wine_from_users(user_rating_df, user, 3)\n",
219
  " wine_recommendation_from_user = f\"Based on user form, we recommend: \"+\"; \".join(wine_recommendation_from_user)\n",
220
- " return wine_recommendation_from_user\n",
221
- " return ''\n",
222
  "\n",
223
  "\n",
224
  "\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_4768/3788270293.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 0x2b30dab90>"
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
+ "name": "stdout",
54
+ "output_type": "stream",
55
+ "text": [
56
+ "0\n"
57
+ ]
58
  }
59
  ],
60
  "source": [
 
178
  " # Button to submit the form\n",
179
  " html.Button('Recommend Wine', id='recommend-wine-from-form', n_clicks=0),\n",
180
  " html.Div(id='recommended-wine-form-output', style={'textAlign':'center'}),\n",
 
 
 
 
 
 
 
181
  "], style={'background-color': '#333', 'font-family': 'Fantasy', 'color': '#999', 'padding': '10px'})\n",
182
  "\n",
 
183
  "@app.callback(\n",
184
+ " Output('recommend-wine-from-form-reset', 'n_clicks'),\n",
185
  " Input('recommend-wine-from-form-reset', 'n_clicks'),\n",
186
  ")\n",
187
  "def reset_form(n_clicks):\n",
188
+ " print(n_clicks)\n",
189
  " if n_clicks > 0:\n",
190
  " TEMPORARY_WINE_RECOMMENDATION_FORM_INFO.clear()\n",
191
+ " return 0\n",
192
  " \n",
193
  "\n",
194
  "@app.callback(\n",
195
  " Output('recommended-wine-rating-info', 'children'),\n",
196
+ " Output('submit-button', 'n_clicks'),\n",
197
  " Input('submit-button', 'n_clicks'),\n",
198
  " Input('dropdown-selection', 'value'),\n",
199
  " Input('input-wine-rating', 'value'),\n",
 
201
  "def update_output(n_clicks, wine_name, rating):\n",
202
  " if n_clicks > 0:\n",
203
  " TEMPORARY_WINE_RECOMMENDATION_FORM_INFO[wine_name] = rating\n",
204
+ " return f'You rated {wine_name} with a score of {rating}', 0\n",
205
+ " return '', 0\n",
 
206
  "\n",
207
  "@app.callback(\n",
208
  " Output('recommended-wine-form-output', 'children'),\n",
209
+ " Output('recommend-wine-from-form', 'n_clicks'),\n",
210
  " Input('recommend-wine-from-form', 'n_clicks'),\n",
211
  ")\n",
212
  "def recommend_wine_from_form(n_clicks):\n",
 
219
  "\n",
220
  " wine_recommendation_from_user = core.recommend_wine_from_users(user_rating_df, user, 3)\n",
221
  " wine_recommendation_from_user = f\"Based on user form, we recommend: \"+\"; \".join(wine_recommendation_from_user)\n",
222
+ " return wine_recommendation_from_user, 0\n",
223
+ " return '', 0\n",
224
  "\n",
225
  "\n",
226
  "\n",