OmPrakashSingh1704 commited on
Commit
3003fc6
1 Parent(s): 7f658aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -33,12 +33,14 @@ with open('items_dict.pkl', 'rb') as file:
33
 
34
  mode = st.toggle(label="MART")
35
 
 
 
36
 
37
  def get_recommendations(user_description, count_vectorizer, count_matrix):
38
  user_description = preprocess_text(user_description)
39
  user_vector = count_vectorizer.transform([user_description])
40
  cosine_similarities = cosine_similarity(user_vector, count_matrix).flatten()
41
- similar_indices = cosine_similarities.argsort()[::-1][:5]
42
  return similar_indices
43
 
44
 
@@ -57,8 +59,10 @@ def show_recipe(recipe):
57
  cont = st.container(border=True, height=500)
58
  cont.write(ingredients)
59
  for j, i in enumerate(recipe["ingredients"]):
 
 
60
  cont.selectbox(i['name'],
61
- options=items_dict.iloc[get_recommendations(i['name'], cv, vectors)][
62
  "PRODUCT_NAME"].values,
63
  key=f"selectbox_{j}_{i['name']}{random.random() * 100}")
64
  with col02:
 
33
 
34
  mode = st.toggle(label="MART")
35
 
36
+ if 'ind' not in st.session_state:
37
+ st.session_state.ind = []
38
 
39
  def get_recommendations(user_description, count_vectorizer, count_matrix):
40
  user_description = preprocess_text(user_description)
41
  user_vector = count_vectorizer.transform([user_description])
42
  cosine_similarities = cosine_similarity(user_vector, count_matrix).flatten()
43
+ similar_indices = cosine_similarities.argsort()[::-1]
44
  return similar_indices
45
 
46
 
 
59
  cont = st.container(border=True, height=500)
60
  cont.write(ingredients)
61
  for j, i in enumerate(recipe["ingredients"]):
62
+ ind = get_recommendations(i['name'], cv, vectors)
63
+ st.session_state.ind.append(ind[:5].tolist())
64
  cont.selectbox(i['name'],
65
+ options=items_dict.iloc[ind][
66
  "PRODUCT_NAME"].values,
67
  key=f"selectbox_{j}_{i['name']}{random.random() * 100}")
68
  with col02: