Spaces:
Running
Running
David Chuan-En Lin
commited on
Commit
Β·
8693708
1
Parent(s):
eca4c19
UI/UX updates
Browse files- foodnet.py +7 -3
foodnet.py
CHANGED
@@ -222,8 +222,9 @@ def plot_results(names, probs, n=5):
|
|
222 |
ax.set_ylabel('Probability',fontsize='large', fontweight='bold')
|
223 |
ax.set_xlabel('Ingredients', fontsize='large', fontweight='bold')
|
224 |
ax.xaxis.labelpad = 10
|
225 |
-
ax.set_title(f'
|
226 |
# mpld3.show()
|
|
|
227 |
fig = plt.gcf()
|
228 |
|
229 |
return fig
|
@@ -243,13 +244,16 @@ model, yum = load_model('fastfood.pth')
|
|
243 |
if add_selectbox == "FoodNet Recommender":
|
244 |
st.title("FoodNet π")
|
245 |
st.write("Search for similar food ingredients. Select two or more ingredients to find complementary ingredients.")
|
246 |
-
|
|
|
|
|
247 |
|
248 |
## Slider ##
|
249 |
st.slider("Number of recommendations to show", min_value=1, max_value=100, value=5, step=1, key='top_n')
|
250 |
|
251 |
## Get food recommendation ##
|
252 |
-
|
|
|
253 |
names = [o[0] for o in out]
|
254 |
probs = [o[1] for o in out]
|
255 |
|
|
|
222 |
ax.set_ylabel('Probability',fontsize='large', fontweight='bold')
|
223 |
ax.set_xlabel('Ingredients', fontsize='large', fontweight='bold')
|
224 |
ax.xaxis.labelpad = 10
|
225 |
+
ax.set_title(f'FoodNet Top {n} Predictions = {st.session_state.leftovers}')
|
226 |
# mpld3.show()
|
227 |
+
plt.xticks(rotation=45, ha='right')
|
228 |
fig = plt.gcf()
|
229 |
|
230 |
return fig
|
|
|
244 |
if add_selectbox == "FoodNet Recommender":
|
245 |
st.title("FoodNet π")
|
246 |
st.write("Search for similar food ingredients. Select two or more ingredients to find complementary ingredients.")
|
247 |
+
ingredients = list(yum.key_to_index.keys())
|
248 |
+
ingredients = [x.replace('_',' ') for x in ingredients]
|
249 |
+
st.multiselect("Type or select food ingredients", ingredients, default=['bread', 'lettuce'], key="leftovers")
|
250 |
|
251 |
## Slider ##
|
252 |
st.slider("Number of recommendations to show", min_value=1, max_value=100, value=5, step=1, key='top_n')
|
253 |
|
254 |
## Get food recommendation ##
|
255 |
+
ingredients_no_space = [x.replace(' ','_') for x in st.session_state.get('leftovers')]
|
256 |
+
out = recommend_ingredients(yum, ingredients_no_space, n=st.session_state.top_n)
|
257 |
names = [o[0] for o in out]
|
258 |
probs = [o[1] for o in out]
|
259 |
|