David Chuan-En Lin commited on
Commit
75d1bdf
β€’
1 Parent(s): 8693708

Add dietary restrictions functionality

Browse files
Files changed (2) hide show
  1. blacklists.py +7 -0
  2. foodnet.py +85 -15
blacklists.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+
2
+
3
+ vegitarian = ['beef', 'chicken', 'turkey', 'pork', 'fish', 'salmon',
4
+ 'steak', 'tuna', 'crab', 'lobster', 'bacon', 'ham', 'scallops',
5
+ 'mussles', 'bologna']
6
+
7
+ kosher = ['pork', 'crab', 'lobster', 'bacon', 'ham', 'scallops', 'mussles', 'bologna']
foodnet.py CHANGED
@@ -16,6 +16,21 @@ from concurrent.futures import ProcessPoolExecutor
16
  import matplotlib.pyplot as plt
17
  import streamlit as st
18
  import argparse
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  from PIL import Image
20
 
21
 
@@ -239,7 +254,7 @@ st.set_page_config(page_title="FoodNet", page_icon = "πŸ”", layout = "centered"
239
  ## Sidebar ##
240
  add_selectbox = st.sidebar.selectbox("Pages", ("FoodNet Recommender", "Food Donation Resources", "Contact Team"))
241
 
242
- model, yum = load_model('fastfood.pth')
243
 
244
  if add_selectbox == "FoodNet Recommender":
245
  st.title("FoodNet πŸ”")
@@ -251,28 +266,80 @@ if add_selectbox == "FoodNet Recommender":
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
 
260
- if 'probs' not in st.session_state:
261
- st.session_state['probs'] = False
262
 
263
- if st.session_state.probs:
264
- st.table(data=out)
265
- else:
266
- st.table(data=names)
267
 
268
- st.checkbox(label="Show model scores", value=False, key="probs")
269
- ## Plot Results ##
270
- st.checkbox(label="Show results bar chart", value=False, key="plot")
271
- if st.session_state.plot:
272
- fig = plot_results(names, probs, st.session_state.top_n)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
 
274
- ## Show Plot ##
275
- st.pyplot(fig)
 
 
 
 
 
276
 
277
  elif add_selectbox == "Food Donation Resources":
278
  st.title('Food Donation Resources')
@@ -326,7 +393,10 @@ if add_selectbox == "Contact Team":
326
  col1, mid, col2 = st.columns([20, 2, 10])
327
  with col1:
328
  st.write('Pronouns: he/him/his')
 
329
  st.write('Favorite Food: Deep Dish Pizza')
 
 
330
  st.write('Email: [email protected]')
331
  with col2:
332
  st.image('https://images.squarespace-cdn.com/content/v1/562661f3e4b0ae7c10f0a2cc/1590528961389-2142HA48O7LRZ9FWGP0F/about_image.jpg?format=2500w', width=300)
@@ -353,4 +423,4 @@ if add_selectbox == "Contact Team":
353
  st.write('Hobbies: photography')
354
  st.write('Email: [email protected]')
355
  with col2:
356
- st.image('https://scontent-ort2-1.xx.fbcdn.net/v/t39.30808-6/261420667_131245119324840_3342182275866550937_n.jpg?_nc_cat=100&ccb=1-5&_nc_sid=730e14&_nc_ohc=IP7khn2w6cwAX_wC85x&_nc_ht=scontent-ort2-1.xx&oh=063c2b6b0ed5e9fc10adb2c391c471cf&oe=61AA72C1', width=300)
 
16
  import matplotlib.pyplot as plt
17
  import streamlit as st
18
  import argparse
19
+ import logging
20
+ from pyunsplash import PyUnsplash
21
+ import blacklists
22
+ api_key = 'hzcKZ0e4we95wSd8_ip2zTB3m2DrOMWehAxrYjqjwg0'
23
+
24
+ # instantiate PyUnsplash object
25
+ py_un = PyUnsplash(api_key=api_key)
26
+
27
+ # pyunsplash logger defaults to level logging.ERROR
28
+ # If you need to change that, use getLogger/setLevel
29
+ # on the module logger, like this:
30
+ logging.getLogger("pyunsplash").setLevel(logging.DEBUG)
31
+
32
+ # TODO:
33
+ # Image search: Option 1 -> google image search api || Option 2 -> open ai clip search
34
  from PIL import Image
35
 
36
 
 
254
  ## Sidebar ##
255
  add_selectbox = st.sidebar.selectbox("Pages", ("FoodNet Recommender", "Food Donation Resources", "Contact Team"))
256
 
257
+ model, yum = load_model()
258
 
259
  if add_selectbox == "FoodNet Recommender":
260
  st.title("FoodNet πŸ”")
 
266
  ## Slider ##
267
  st.slider("Number of recommendations to show", min_value=1, max_value=100, value=5, step=1, key='top_n')
268
 
269
+ ## Show Images ##
270
+ # search = py_un.search(type_="photos", query="cookie")
271
+ # py_un.photos(type_="single", photo_id='l0_kVknpO2g')
272
+
273
+ # st.image(search)
274
+ ## Images
275
+ # for leftover in st.session_state.leftovers:
276
+ # search = py_un.search(type_='photos', query=leftover)
277
+ # for photo in search.entries:
278
+ # # print(photo.id, photo.link_download)
279
+ # st.image(photo.link_download, caption=leftover, width=200)
280
+ # break
281
+ # (f"![Alt Text]({search.link_next})")
282
+
283
  ## Get food recommendation ##
284
  ingredients_no_space = [x.replace(' ','_') for x in st.session_state.get('leftovers')]
285
  out = recommend_ingredients(yum, ingredients_no_space, n=st.session_state.top_n)
286
  names = [o[0] for o in out]
287
  probs = [o[1] for o in out]
288
 
289
+ # if 'probs' not in st.session_state:
290
+ # st.session_state['probs'] = False
291
 
292
+ # if st.session_state.probs:
293
+ # st.table(data=out)
294
+ # else:
295
+ # st.table(data=names)
296
 
297
+ # st.checkbox(label="Show model scores", value=False, key="probs")
298
+ # ## Plot Results ##
299
+ # st.checkbox(label="Show results bar chart", value=False, key="plot")
300
+ # if st.session_state.plot:
301
+ # fig = plot_results(names, probs, st.session_state.top_n)
302
+
303
+ # ## Show Plot ##
304
+ # st.pyplot(fig)
305
+ st.selectbox(label="Dietary Resriction", options=('None', 'Kosher', 'Vegitarian'), key="diet")
306
+ if st.session_state.diet != 'None':
307
+ if st.session_state.diet == 'Vegitarian':
308
+ out = [o for o in out if not any(ignore in o[0] for ignore in blacklists.vegitarian)]
309
+ if st.session_state.diet == "Kosher":
310
+ out = [o for o in out if not any(ignore in o[0] for ignore in blacklists.kosher)]
311
+ names = [o[0] for o in out]
312
+ probs = [o[1] for o in out]
313
+
314
+ col1, col2, col3 = st.columns(3)
315
+
316
+ # st.checkbox(label="Show model score", value=False, key="probs")
317
+ # if st.session_state.probs:
318
+ # col1.table(data=out)
319
+ # else:
320
+ # col1.table(data=names)
321
+
322
+ for i, name in enumerate(names):
323
+ search = py_un.search(type_='photos', query=name)
324
+ for photo in search.entries:
325
+ col_id = i%3
326
+ if col_id == 0:
327
+ col1.image(photo.link_download, caption=name, use_column_width=True)
328
+ elif col_id == 1:
329
+ col2.image(photo.link_download, caption=name, use_column_width=True)
330
+ elif col_id == 2:
331
+ col3.image(photo.link_download, caption=name, use_column_width=True)
332
+ # print(photo.id, photo.link_download)
333
+
334
+ break
335
 
336
+ ## Plot Results ##
337
+ # st.checkbox(label="Show model bar chart", value=False, key="plot")
338
+ # if st.session_state.plot:
339
+ # fig = plot_results(names, probs, st.session_state.top_n)
340
+
341
+ # ## Show Plot ##
342
+ # col2.pyplot(fig)
343
 
344
  elif add_selectbox == "Food Donation Resources":
345
  st.title('Food Donation Resources')
 
393
  col1, mid, col2 = st.columns([20, 2, 10])
394
  with col1:
395
  st.write('Pronouns: he/him/his')
396
+ st.write('Research/career interests: Robotics, AI')
397
  st.write('Favorite Food: Deep Dish Pizza')
398
+ st.write('A painfully boring fact: Am a middle child')
399
+ st.write('Hobbies: Golf, Traveling, Games')
400
  st.write('Email: [email protected]')
401
  with col2:
402
  st.image('https://images.squarespace-cdn.com/content/v1/562661f3e4b0ae7c10f0a2cc/1590528961389-2142HA48O7LRZ9FWGP0F/about_image.jpg?format=2500w', width=300)
 
423
  st.write('Hobbies: photography')
424
  st.write('Email: [email protected]')
425
  with col2:
426
+ st.image('https://scontent-ort2-1.xx.fbcdn.net/v/t39.30808-6/261420667_131245119324840_3342182275866550937_n.jpg?_nc_cat=100&ccb=1-5&_nc_sid=730e14&_nc_ohc=IP7khn2w6cwAX_wC85x&_nc_ht=scontent-ort2-1.xx&oh=063c2b6b0ed5e9fc10adb2c391c471cf&oe=61AA72C1', width=300)