Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,22 +11,16 @@ st.set_page_config(layout="wide")
|
|
11 |
|
12 |
login(token=os.getenv("TOKEN"))
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
st.error("The items dictionary file was not found.")
|
25 |
-
|
26 |
-
try:
|
27 |
-
data = pd.read_csv('marketing_sample_for_walmart_com-product_details__20200101_20200331__30k_data.csv')
|
28 |
-
except FileNotFoundError:
|
29 |
-
st.error("The CSV file was not found.")
|
30 |
|
31 |
# Initialize the inference client for the Mixtral model
|
32 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
@@ -49,6 +43,12 @@ if 'selected_difficulty' not in st.session_state:
|
|
49 |
if 'exclusions' not in st.session_state:
|
50 |
st.session_state.exclusions = None
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
|
54 |
if difficulty == "Quick & Easy":
|
@@ -239,8 +239,8 @@ if st.session_state.recipe is not None:
|
|
239 |
name_and_dis = f'# {recipe["name"]}\n\n'
|
240 |
name_and_dis += f'{recipe["description"]}\n\n'
|
241 |
ingredients = '## Ingredients:\n'
|
242 |
-
for ingredient in recipe["ingredients"]:
|
243 |
-
|
244 |
instructions = '\n## Instructions:\n'
|
245 |
for instruction in recipe["instructions"]:
|
246 |
instructions += f"{instruction['step_number']}. {instruction['instruction']}\n"
|
@@ -248,10 +248,11 @@ if st.session_state.recipe is not None:
|
|
248 |
st.write(name_and_dis)
|
249 |
col01, col02 = st.columns(2)
|
250 |
with col01:
|
251 |
-
cont = st.container()
|
252 |
-
|
|
|
253 |
with col02:
|
254 |
-
cont = st.container()
|
255 |
cont.write(instructions)
|
256 |
except (json.JSONDecodeError, KeyError) as e:
|
257 |
st.error(f"Failed to parse recipe: {e}")
|
|
|
11 |
|
12 |
login(token=os.getenv("TOKEN"))
|
13 |
|
14 |
+
with open('cv.pkl', 'rb') as file:
|
15 |
+
cv = pickle.load(file)
|
16 |
+
|
17 |
+
with open('vectors.pkl', 'rb') as file:
|
18 |
+
vectors = pickle.load(file)
|
19 |
+
|
20 |
+
with open('items_dict.pkl', 'rb') as file:
|
21 |
+
items_dict = pd.DataFrame.from_dict(pickle.load(file))
|
22 |
+
|
23 |
+
data = pd.read_csv('marketing_sample_for_walmart_com-product_details__20200101_20200331__30k_data.csv')
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
# Initialize the inference client for the Mixtral model
|
26 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
|
43 |
if 'exclusions' not in st.session_state:
|
44 |
st.session_state.exclusions = None
|
45 |
|
46 |
+
def get_recommendations(user_description, count_vectorizer, count_matrix):
|
47 |
+
user_description = preprocess_text(user_description)
|
48 |
+
user_vector = count_vectorizer.transform([user_description])
|
49 |
+
cosine_similarities = cosine_similarity(user_vector, count_matrix).flatten()
|
50 |
+
similar_indices = cosine_similarities.argsort()[::-1]
|
51 |
+
return similar_indices
|
52 |
|
53 |
def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
|
54 |
if difficulty == "Quick & Easy":
|
|
|
239 |
name_and_dis = f'# {recipe["name"]}\n\n'
|
240 |
name_and_dis += f'{recipe["description"]}\n\n'
|
241 |
ingredients = '## Ingredients:\n'
|
242 |
+
# for ingredient in recipe["ingredients"]:
|
243 |
+
# ingredients += f"- {ingredient['name']}\n"
|
244 |
instructions = '\n## Instructions:\n'
|
245 |
for instruction in recipe["instructions"]:
|
246 |
instructions += f"{instruction['step_number']}. {instruction['instruction']}\n"
|
|
|
248 |
st.write(name_and_dis)
|
249 |
col01, col02 = st.columns(2)
|
250 |
with col01:
|
251 |
+
cont = st.container(border=True, height=500)
|
252 |
+
for i in recipe["ingredients"]:
|
253 |
+
cont.selectbox(i['name'],options=items_dict.iloc[get_recommendations(i['name'],cv,vectors)]["Product Name"].values)
|
254 |
with col02:
|
255 |
+
cont = st.container(border=True, height=500)
|
256 |
cont.write(instructions)
|
257 |
except (json.JSONDecodeError, KeyError) as e:
|
258 |
st.error(f"Failed to parse recipe: {e}")
|