Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,13 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
-
import re
|
3 |
-
import json
|
4 |
-
import os,secrets
|
5 |
import pandas as pd
|
6 |
from huggingface_hub import login, InferenceClient
|
7 |
-
import pickle
|
|
|
8 |
from sklearn.metrics.pairwise import cosine_similarity
|
|
|
|
|
9 |
|
10 |
st.set_page_config(layout="wide")
|
11 |
|
@@ -41,12 +43,16 @@ def show_recipe(recipe):
|
|
41 |
col01, col02 = st.columns(2)
|
42 |
with col01:
|
43 |
cont = st.container(border=True, height=500)
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
46 |
with col02:
|
47 |
cont = st.container(border=True, height=500)
|
48 |
cont.write(instructions)
|
49 |
|
|
|
50 |
# Initialize the inference client for the Mixtral model
|
51 |
if not mode:
|
52 |
cook,saved=st.tabs(['COOK','SAVED'])
|
@@ -288,6 +294,7 @@ if not mode:
|
|
288 |
print(st.session_state.recipe)
|
289 |
recipe = json.loads(st.session_state.recipe)
|
290 |
show_recipe(recipe)
|
|
|
291 |
if st.session_state.recipe_saved == True:
|
292 |
disable_button = True
|
293 |
else:
|
@@ -301,4 +308,48 @@ if not mode:
|
|
301 |
st.empty()
|
302 |
if st.session_state.recipe_saved == True:
|
303 |
st.success("Recipe Saved!")
|
304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
import streamlit as st
|
3 |
+
import re, ast, secrets, os, json
|
|
|
|
|
4 |
import pandas as pd
|
5 |
from huggingface_hub import login, InferenceClient
|
6 |
+
import pickle,datetime
|
7 |
+
from functools import partial
|
8 |
from sklearn.metrics.pairwise import cosine_similarity
|
9 |
+
import datetime
|
10 |
+
|
11 |
|
12 |
st.set_page_config(layout="wide")
|
13 |
|
|
|
43 |
col01, col02 = st.columns(2)
|
44 |
with col01:
|
45 |
cont = st.container(border=True, height=500)
|
46 |
+
cont.write(ingredients)
|
47 |
+
for j, i in enumerate(recipe["ingredients"]):
|
48 |
+
cont.selectbox(i['name'],
|
49 |
+
options=items_dict.iloc[get_recommendations(i['name'], cv, vectors)]["PRODUCT_NAME"].values,
|
50 |
+
key=f"selectbox_{j}_{i['name']}{random.random()*100}")
|
51 |
with col02:
|
52 |
cont = st.container(border=True, height=500)
|
53 |
cont.write(instructions)
|
54 |
|
55 |
+
|
56 |
# Initialize the inference client for the Mixtral model
|
57 |
if not mode:
|
58 |
cook,saved=st.tabs(['COOK','SAVED'])
|
|
|
294 |
print(st.session_state.recipe)
|
295 |
recipe = json.loads(st.session_state.recipe)
|
296 |
show_recipe(recipe)
|
297 |
+
recipe['timestamp'] = str(datetime.datetime.now())
|
298 |
if st.session_state.recipe_saved == True:
|
299 |
disable_button = True
|
300 |
else:
|
|
|
308 |
st.empty()
|
309 |
if st.session_state.recipe_saved == True:
|
310 |
st.success("Recipe Saved!")
|
311 |
+
with saved:
|
312 |
+
st.title("Saved Recipes")
|
313 |
+
def load_saved_recipes_from_pickle(directory_path):
|
314 |
+
recipes = []
|
315 |
+
# Iterate through all files in the directory
|
316 |
+
for filename in os.listdir(directory_path):
|
317 |
+
if filename.endswith('.pkl'):
|
318 |
+
file_path = os.path.join(directory_path, filename)
|
319 |
+
with open(file_path, 'rb') as file:
|
320 |
+
recipe = pickle.load(file)
|
321 |
+
recipes.append(recipe)
|
322 |
+
return recipes
|
323 |
+
|
324 |
+
|
325 |
+
# get all saved files
|
326 |
+
directory_path = r"./data/" # Update this path if needed
|
327 |
+
recipes = load_saved_recipes_from_pickle(directory_path)
|
328 |
+
print(recipes)
|
329 |
+
|
330 |
+
cols = st.columns([4, 1])
|
331 |
+
with cols[1]:
|
332 |
+
user_sort = st.selectbox("Sort", ('Recent', 'Oldest', 'A-Z', 'Z-A', 'Random'))
|
333 |
+
if user_sort == 'Recent':
|
334 |
+
recipes.sort(key=lambda x: x['timestamp'], reverse=True)
|
335 |
+
elif user_sort == 'Oldest':
|
336 |
+
recipes.sort(key=lambda x: x['timestamp'])
|
337 |
+
elif user_sort == 'A-Z':
|
338 |
+
recipes.sort(key=lambda x: x['name'])
|
339 |
+
elif user_sort == 'Z-A':
|
340 |
+
recipes.sort(key=lambda x: x['name'], reverse=True)
|
341 |
+
elif user_sort == 'Random':
|
342 |
+
recipes.sort(key=lambda x: x['file'])
|
343 |
+
with cols[0]:
|
344 |
+
user_search = st.selectbox("Search Recipes", [""] + [recipe['name'] for recipe in recipes])
|
345 |
+
st.write("") # just some space
|
346 |
+
|
347 |
+
if user_search!="":
|
348 |
+
with st.spinner('LOADING YOUR RECIPE...'):
|
349 |
+
st.divider()
|
350 |
+
filtered_recipes = [recipe for recipe in recipes if recipe['name'] == user_search]
|
351 |
+
if filtered_recipes:
|
352 |
+
show_recipe(filtered_recipes[0])
|
353 |
+
else:
|
354 |
+
st.write("No recipe found.")
|
355 |
+
|