Spaces:
Sleeping
Sleeping
OmPrakashSingh1704
commited on
Commit
•
c910c88
1
Parent(s):
580dd3e
Update app.py
Browse files
app.py
CHANGED
@@ -31,29 +31,31 @@ def get_recommendations(user_description, count_vectorizer, count_matrix):
|
|
31 |
similar_indices = cosine_similarities.argsort()[::-1]
|
32 |
return similar_indices
|
33 |
|
|
|
34 |
def show_recipe(recipe):
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
|
56 |
# Initialize the inference client for the Mixtral model
|
|
|
57 |
if not mode:
|
58 |
cook,saved=st.tabs(['COOK','SAVED'])
|
59 |
with cook:
|
@@ -187,6 +189,7 @@ if not mode:
|
|
187 |
st.session_state.exclusions = None
|
188 |
st.session_state.serving_size = 2
|
189 |
st.session_state.selected_difficulty = "Quick & Easy"
|
|
|
190 |
|
191 |
|
192 |
st.title("Let's get cooking")
|
@@ -303,47 +306,47 @@ if not mode:
|
|
303 |
st.success("Recipe Saved!")
|
304 |
with saved:
|
305 |
st.title("Saved Recipes")
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
st.divider()
|
344 |
filtered_recipes = [recipe for recipe in recipes if recipe['name'] == user_search]
|
345 |
if filtered_recipes:
|
346 |
show_recipe(filtered_recipes[0])
|
347 |
else:
|
348 |
st.write("No recipe found.")
|
349 |
-
|
|
|
31 |
similar_indices = cosine_similarities.argsort()[::-1]
|
32 |
return similar_indices
|
33 |
|
34 |
+
@st.cache_data(show_spinner=True)
|
35 |
def show_recipe(recipe):
|
36 |
+
with st.spinner("HANG TIGHT, RECIPE INCOMING..."):
|
37 |
+
name_and_dis = f'# {recipe["name"]}\n\n'
|
38 |
+
name_and_dis += f'{recipe["description"]}\n\n'
|
39 |
+
ingredients = '## Ingredients:\n'
|
40 |
+
instructions = '\n## Instructions:\n'
|
41 |
+
for instruction in recipe["instructions"]:
|
42 |
+
instructions += f"{instruction['step_number']}. {instruction['instruction']}\n"
|
43 |
+
|
44 |
+
st.write(name_and_dis)
|
45 |
+
col01, col02 = st.columns(2)
|
46 |
+
with col01:
|
47 |
+
cont = st.container(border=True, height=500)
|
48 |
+
cont.write(ingredients)
|
49 |
+
for j, i in enumerate(recipe["ingredients"]):
|
50 |
+
cont.selectbox(i['name'],
|
51 |
+
options=items_dict.iloc[get_recommendations(i['name'], cv, vectors)]["PRODUCT_NAME"].values,
|
52 |
+
key=f"selectbox_{j}_{i['name']}{random.random()*100}")
|
53 |
+
with col02:
|
54 |
+
cont = st.container(border=True, height=500)
|
55 |
+
cont.write(instructions)
|
56 |
|
57 |
# Initialize the inference client for the Mixtral model
|
58 |
+
|
59 |
if not mode:
|
60 |
cook,saved=st.tabs(['COOK','SAVED'])
|
61 |
with cook:
|
|
|
189 |
st.session_state.exclusions = None
|
190 |
st.session_state.serving_size = 2
|
191 |
st.session_state.selected_difficulty = "Quick & Easy"
|
192 |
+
st.session_state.recipe=None
|
193 |
|
194 |
|
195 |
st.title("Let's get cooking")
|
|
|
306 |
st.success("Recipe Saved!")
|
307 |
with saved:
|
308 |
st.title("Saved Recipes")
|
309 |
+
with st.spinner('LOADING YOUR RECIPE...'):
|
310 |
+
def load_saved_recipes_from_pickle(directory_path):
|
311 |
+
os.makedirs('data', exist_ok=True)
|
312 |
+
recipes = []
|
313 |
+
# Iterate through all files in the directory
|
314 |
+
for filename in os.listdir(directory_path):
|
315 |
+
if filename.endswith('.pkl'):
|
316 |
+
file_path = os.path.join(directory_path, filename)
|
317 |
+
with open(file_path, 'rb') as file:
|
318 |
+
recipe = pickle.load(file)
|
319 |
+
recipes.append(recipe)
|
320 |
+
return recipes
|
321 |
+
|
322 |
+
|
323 |
+
# get all saved files
|
324 |
+
directory_path = 'data'
|
325 |
+
recipes = load_saved_recipes_from_pickle(directory_path)
|
326 |
+
print(recipes)
|
327 |
+
|
328 |
+
cols = st.columns([4, 1])
|
329 |
+
with cols[1]:
|
330 |
+
user_sort = st.selectbox("Sort", ('Recent', 'Oldest', 'A-Z', 'Z-A', 'Random'))
|
331 |
+
if user_sort == 'Recent':
|
332 |
+
recipes.sort(key=lambda x: x['timestamp'], reverse=True)
|
333 |
+
elif user_sort == 'Oldest':
|
334 |
+
recipes.sort(key=lambda x: x['timestamp'])
|
335 |
+
elif user_sort == 'A-Z':
|
336 |
+
recipes.sort(key=lambda x: x['name'])
|
337 |
+
elif user_sort == 'Z-A':
|
338 |
+
recipes.sort(key=lambda x: x['name'], reverse=True)
|
339 |
+
elif user_sort == 'Random':
|
340 |
+
recipes.sort(key=lambda x: x['file'])
|
341 |
+
with cols[0]:
|
342 |
+
user_search = st.selectbox("Search Recipes", [""] + [recipe['name'] for recipe in recipes])
|
343 |
+
st.write("") # just some space
|
344 |
+
|
345 |
+
if user_search!="":
|
346 |
st.divider()
|
347 |
filtered_recipes = [recipe for recipe in recipes if recipe['name'] == user_search]
|
348 |
if filtered_recipes:
|
349 |
show_recipe(filtered_recipes[0])
|
350 |
else:
|
351 |
st.write("No recipe found.")
|
352 |
+
|