Spaces:
Running
Running
David Chuan-En Lin
commited on
Commit
Β·
7d9242a
1
Parent(s):
6f540cc
Add food donation resources page and contacts page
Browse files- .DS_Store +0 -0
- foodnet.py +111 -51
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
foodnet.py
CHANGED
@@ -16,6 +16,7 @@ from concurrent.futures import ProcessPoolExecutor
|
|
16 |
import matplotlib.pyplot as plt
|
17 |
import streamlit as st
|
18 |
import argparse
|
|
|
19 |
|
20 |
|
21 |
# NLTK Datasets
|
@@ -39,7 +40,9 @@ def recommend_ingredients(yum, leftovers, n=10):
|
|
39 |
leftovers_embedding_sum = np.zeros([32,])
|
40 |
for ingredient in leftovers:
|
41 |
# pdb.set_trace()
|
|
|
42 |
ingredient_embedding = yum.get_vector(ingredient, norm=True)
|
|
|
43 |
leftovers_embedding_sum += ingredient_embedding
|
44 |
leftovers_embedding = leftovers_embedding_sum / len(leftovers) # Embedding for leftovers
|
45 |
top_matches = yum.similar_by_vector(leftovers_embedding, topn=100)
|
@@ -88,7 +91,7 @@ def recommend_ingredients_subsets(model, yum,leftovers, subset_size):
|
|
88 |
'''
|
89 |
all_outputs = {}
|
90 |
for leftovers_subset in itertools.combinations(leftovers, subset_size):
|
91 |
-
leftovers_embedding_sum = np.
|
92 |
for ingredient in leftovers_subset:
|
93 |
ingredient_embedding = yum.word_vec(ingredient, use_norm=True)
|
94 |
leftovers_embedding_sum += ingredient_embedding
|
@@ -225,68 +228,125 @@ def plot_results(names, probs, n=5):
|
|
225 |
|
226 |
return fig
|
227 |
|
|
|
|
|
|
|
228 |
|
229 |
-
|
230 |
-
# Initialize argparse
|
231 |
-
# parser = argparse.ArgumentParser()
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
# Arguments
|
238 |
-
# parser.add_argument('-d', '--dataset', default=data_path, type=str, help="the filepath of the dataset")
|
239 |
-
# parser.add_argument('-t', '--train', default=False, type=bool, help="the filepath of the dataset")
|
240 |
-
# parser.add_argument('-m', '--model', default=model_path, type=str, help="the filepath of the dataset")
|
241 |
|
242 |
-
|
243 |
-
# print(args)
|
244 |
-
|
245 |
-
|
246 |
-
## Train or Test ##
|
247 |
-
# if args.train:
|
248 |
-
# # Load Dataset
|
249 |
-
|
250 |
-
# data = load_data(args.dataset) #pickle.load(open(args.dataset, 'rb'))
|
251 |
-
# # model = train_model(data)
|
252 |
-
# # model_path = input("Model filename and directory [eg. models/new_model.model]: ")
|
253 |
-
# # model.save(model_path)
|
254 |
-
# else:
|
255 |
-
# gdown.download('https://drive.google.com/uc?id=1fXGsWEbr-1BftKtOsnxc61cM3akMAIC0', 'fastfood.pth')
|
256 |
-
# gdown.download('https://drive.google.com/uc?id=1h_TijdSw1K9RT3dnlfIg4xtl8WPNNQmn', 'fastfood.pth.wv.vectors_ngrams.npy')
|
257 |
-
model, yum = load_model('fastfood.pth')
|
258 |
-
|
259 |
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
"
|
264 |
-
("FastFood Recommendation Model", "Food Donation Resources", "Contact Team")
|
265 |
-
)
|
266 |
|
267 |
-
##
|
268 |
-
st.
|
269 |
-
|
270 |
-
## Slider ##
|
271 |
-
st.slider("Number of Recommendations", min_value=1, max_value=100, value=5, step=1, key='top_n')
|
272 |
|
273 |
## Get food recommendation ##
|
274 |
out = recommend_ingredients(yum, st.session_state.leftovers, n=st.session_state.top_n)
|
275 |
names = [o[0] for o in out]
|
276 |
probs = [o[1] for o in out]
|
277 |
|
278 |
-
|
|
|
|
|
279 |
if st.session_state.probs:
|
280 |
-
|
281 |
else:
|
282 |
-
|
283 |
-
|
|
|
284 |
## Plot Results ##
|
285 |
-
st.checkbox(label="Show
|
286 |
if st.session_state.plot:
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
import matplotlib.pyplot as plt
|
17 |
import streamlit as st
|
18 |
import argparse
|
19 |
+
from PIL import Image
|
20 |
|
21 |
|
22 |
# NLTK Datasets
|
|
|
40 |
leftovers_embedding_sum = np.zeros([32,])
|
41 |
for ingredient in leftovers:
|
42 |
# pdb.set_trace()
|
43 |
+
|
44 |
ingredient_embedding = yum.get_vector(ingredient, norm=True)
|
45 |
+
|
46 |
leftovers_embedding_sum += ingredient_embedding
|
47 |
leftovers_embedding = leftovers_embedding_sum / len(leftovers) # Embedding for leftovers
|
48 |
top_matches = yum.similar_by_vector(leftovers_embedding, topn=100)
|
|
|
91 |
'''
|
92 |
all_outputs = {}
|
93 |
for leftovers_subset in itertools.combinations(leftovers, subset_size):
|
94 |
+
leftovers_embedding_sum = np.empty([100,])
|
95 |
for ingredient in leftovers_subset:
|
96 |
ingredient_embedding = yum.word_vec(ingredient, use_norm=True)
|
97 |
leftovers_embedding_sum += ingredient_embedding
|
|
|
228 |
|
229 |
return fig
|
230 |
|
231 |
+
def load_image(image_file):
|
232 |
+
img = Image.open(image_file)
|
233 |
+
return img
|
234 |
|
235 |
+
st.set_page_config(page_title="FoodNet", page_icon = "π", layout = "centered", initial_sidebar_state = "expanded")
|
|
|
|
|
236 |
|
237 |
+
##### UI/UX #####
|
238 |
+
## Sidebar ##
|
239 |
+
add_selectbox = st.sidebar.selectbox("Pages", ("FoodNet Recommender", "Food Donation Resources", "Contact Team"))
|
|
|
|
|
|
|
|
|
|
|
240 |
|
241 |
+
model, yum = load_model('fastfood.pth')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
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 |
+
st.multiselect("Type or select food ingredients", list(yum.key_to_index.keys()), default=['bread', 'lettuce'], key="leftovers")
|
|
|
|
|
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 |
out = recommend_ingredients(yum, st.session_state.leftovers, n=st.session_state.top_n)
|
253 |
names = [o[0] for o in out]
|
254 |
probs = [o[1] for o in out]
|
255 |
|
256 |
+
if 'probs' not in st.session_state:
|
257 |
+
st.session_state['probs'] = False
|
258 |
+
|
259 |
if st.session_state.probs:
|
260 |
+
st.table(data=out)
|
261 |
else:
|
262 |
+
st.table(data=names)
|
263 |
+
|
264 |
+
st.checkbox(label="Show model scores", value=False, key="probs")
|
265 |
## Plot Results ##
|
266 |
+
st.checkbox(label="Show results bar chart", value=False, key="plot")
|
267 |
if st.session_state.plot:
|
268 |
+
fig = plot_results(names, probs, st.session_state.top_n)
|
269 |
+
|
270 |
+
## Show Plot ##
|
271 |
+
st.pyplot(fig)
|
272 |
+
|
273 |
+
elif add_selectbox == "Food Donation Resources":
|
274 |
+
st.title('Food Donation Resources')
|
275 |
+
st.subheader('Pittsburgh Food Bank:')
|
276 |
+
st.write("In 2000, the Food Bank opened the doors on its facility in Duquesne."
|
277 |
+
"This facility was the first LEED-certified building in Pittsburgh and the first LEED-certified "
|
278 |
+
"food bank in the nation. Learn more about that facility here. "
|
279 |
+
"Today, we work with a network of more than 850 partners across the 11 counties we serve. "
|
280 |
+
"In addition to sourcing, warehousing and distributing food, the Food Bank is actively engaged in "
|
281 |
+
"stabilizing lives and confronting issues of chronic hunger, poor nutrition and health. "
|
282 |
+
"And, through our advocacy efforts, we have become a primary driver in comprehensive anti-hunger "
|
283 |
+
"endeavors regionally, statewide and at the national level."
|
284 |
+
)
|
285 |
+
st.write("Check out this [link](https://pittsburghfoodbank.org/)π")
|
286 |
+
st.subheader('412 Food Rescue:')
|
287 |
+
st.write("412 Food Rescue is a nonprofit organization dedicated to ending hunger by organizing "
|
288 |
+
"volunteers to deliver surplus food to insecure communities instead of landfills."
|
289 |
+
"Since its creation in 2015, the organization has redistributed over three million pounds of food through "
|
290 |
+
"the use of its mobile application, Food Rescue Hero. They are currently rolling out the app nationwide."
|
291 |
+
)
|
292 |
+
st.write("Check out this [link](https://412foodrescue.org/)π")
|
293 |
+
|
294 |
+
# st.subheader('Image')
|
295 |
+
# st.multiselect("Select leftovers:", list(yum.key_to_index.keys()), key="leftovers")
|
296 |
+
# image_file = st.file_uploader("Upload Food Image:", type=["png", "jpg", "jpeg"])
|
297 |
+
# if image_file is not None:
|
298 |
+
# # To See details
|
299 |
+
# file_details = {"filename": image_file.name, "filetype": image_file.type,
|
300 |
+
# "filesize": image_file.size}
|
301 |
+
# st.write(file_details)
|
302 |
+
#
|
303 |
+
# # To View Uploaded Image
|
304 |
+
# st.image(load_image(image_file), width=250)
|
305 |
+
if add_selectbox == "Contact Team":
|
306 |
+
st.title('Contact Team')
|
307 |
+
st.subheader('David Chuan-En Lin')
|
308 |
+
col1, mid, col2 = st.columns([20, 2, 10])
|
309 |
+
with col1:
|
310 |
+
st.write('Pronouns: he/him/his')
|
311 |
+
st.write(
|
312 |
+
'Research/career interests: Human-AI Co-Design by (1) building ML-infused creativity support tools and '
|
313 |
+
'(2) investigating how such tools augment design processes')
|
314 |
+
st.write('Favorite Food: Ice cream sandwich')
|
315 |
+
st.write('A painfully boring fact: Second-year PhD at HCII SCS')
|
316 |
+
st.write('Hobbies: Making travel videos, graphic design, music')
|
317 |
+
st.write('Email: [email protected]')
|
318 |
+
with col2:
|
319 |
+
st.image('https://chuanenlin.com/images/me.jpg', width=300)
|
320 |
+
|
321 |
+
st.subheader('Mitchell Fogelson')
|
322 |
+
col1, mid, col2 = st.columns([20, 2, 10])
|
323 |
+
with col1:
|
324 |
+
st.write('Pronouns: he/him/his')
|
325 |
+
st.write('Favorite Food: Deep Dish Pizza')
|
326 |
+
st.write('Email: [email protected]')
|
327 |
+
with col2:
|
328 |
+
st.image('https://images.squarespace-cdn.com/content/v1/562661f3e4b0ae7c10f0a2cc/1590528961389-2142HA48O7LRZ9FWGP0F/about_image.jpg?format=2500w', width=300)
|
329 |
+
|
330 |
+
st.subheader('Sunny Yang')
|
331 |
+
col1, mid, col2 = st.columns([20, 2, 10])
|
332 |
+
with col1:
|
333 |
+
st.write('Pronouns: She/Her/Hers')
|
334 |
+
st.write('Research/career interests: Product Manager')
|
335 |
+
st.write('Favorite Food: Sushi')
|
336 |
+
st.write('A painfully boring fact: I do not like rainy:(')
|
337 |
+
st.write('Hobbies: Viola, Basketball')
|
338 |
+
st.write('Email: [email protected]')
|
339 |
+
with col2:
|
340 |
+
st.image('https://media-exp1.licdn.com/dms/image/C4D03AQF37KjK_GYwzA/profile-displayphoto-shrink_400_400/0/1638326708803?e=1643846400&v=beta&t=q10CTNCG6h5guez1YT0j4j_oLlrGJB_8NugaBOUSAGg', width=300)
|
341 |
+
|
342 |
+
st.subheader('Shihao Xu')
|
343 |
+
col1, mid, col2 = st.columns([20, 2, 10])
|
344 |
+
with col1:
|
345 |
+
st.write('Pronouns: he/him/his')
|
346 |
+
st.write('Research/career interests: Autonomous Vehicle')
|
347 |
+
st.write('Favorite Food: Dumplings')
|
348 |
+
st.write('A painfully boring fact: Covid is still not gone')
|
349 |
+
st.write('Hobbies: photography')
|
350 |
+
st.write('Email: [email protected]')
|
351 |
+
with col2:
|
352 |
+
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)
|