OmPrakashSingh1704 commited on
Commit
fc17498
·
verified ·
1 Parent(s): 81baa34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -28
app.py CHANGED
@@ -1,15 +1,11 @@
1
- import os
2
- import re
3
- import ast
4
- import json
5
- import pickle
6
- import secrets
7
  import random
8
- import datetime
 
9
  import pandas as pd
10
  from huggingface_hub import login, InferenceClient
 
11
  from sklearn.metrics.pairwise import cosine_similarity
12
- import streamlit as st
13
  import wordcloud
14
  import matplotlib.pyplot as plt
15
  from pygwalker.api.streamlit import StreamlitRenderer
@@ -31,7 +27,7 @@ with open('items_dict.pkl', 'rb') as file:
31
  items_dict = pd.DataFrame.from_dict(pickle.load(file))
32
 
33
 
34
- mode = st.toggle(label="MART")
35
 
36
  if 'ind' not in st.session_state:
37
  st.session_state.ind = []
@@ -71,7 +67,6 @@ def show_recipe(recipe):
71
 
72
 
73
  # Initialize the inference client for the Mixtral model
74
-
75
  if not mode:
76
  cook, saved = st.tabs(['COOK', 'SAVED'])
77
  with cook:
@@ -96,13 +91,6 @@ if not mode:
96
  st.session_state.exclusions = None
97
 
98
 
99
- def preprocess_text(text):
100
- # Remove non-alphabet characters and extra spaces
101
- text = re.sub(r'[^a-zA-Z\s]', '', text)
102
- text = re.sub(r'\s+', ' ', text).strip()
103
- return text.lower()
104
-
105
-
106
  def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
107
  if difficulty == "Quick & Easy":
108
  prompt = (
@@ -127,7 +115,6 @@ if not mode:
127
  )
128
  return prompt
129
 
130
-
131
  def generate_recipe(user_inputs):
132
  with st.spinner('Building the perfect recipe...'):
133
  prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'],
@@ -201,7 +188,6 @@ if not mode:
201
  st.session_state.recipe = response
202
  st.session_state.recipe_saved = False
203
 
204
-
205
  def clear_inputs():
206
  st.session_state.user_direction = None
207
  st.session_state.exclusions = None
@@ -209,7 +195,6 @@ if not mode:
209
  st.session_state.selected_difficulty = "Quick & Easy"
210
  st.session_state.recipe = None
211
 
212
-
213
  st.title("Let's get cooking")
214
  col1, col2 = st.columns(2)
215
  with col1:
@@ -278,14 +263,14 @@ if not mode:
278
 
279
  button_cols_submit = st.columns([1, 1, 4])
280
  with button_cols_submit[0]:
281
- st.button(label='Submit', on_click=generate_recipe, kwargs=dict(user_inputs=user_inputs), type="primary",
 
282
  use_container_width=True)
283
  with button_cols_submit[1]:
284
  st.button(label='Reset', on_click=clear_inputs, type="secondary", use_container_width=True)
285
  with button_cols_submit[2]:
286
  st.empty()
287
 
288
-
289
  def create_safe_filename(recipe_name):
290
  # format and generate random URL-safe text string
291
  safe_name = recipe_name.lower()
@@ -296,7 +281,6 @@ if not mode:
296
  safe_filename = f"{unique_token}_{safe_name}"
297
  return safe_filename
298
 
299
-
300
  def save_recipe():
301
  with st.spinner('WAIT SAVING YOUR DISH...'):
302
  filename = create_safe_filename(recipe["name"])
@@ -305,13 +289,11 @@ if not mode:
305
  pickle.dump(recipe, f)
306
  st.session_state.recipe_saved = True
307
 
308
-
309
  if st.session_state.recipe is not None:
310
  st.divider()
311
  print(st.session_state.recipe)
312
  recipe = json.loads(st.session_state.recipe)
313
- if not st.session_state.recipe_saved:
314
- show_recipe(recipe)
315
  recipe['timestamp'] = str(datetime.datetime.now())
316
  if st.session_state.recipe_saved == True:
317
  disable_button = True
@@ -341,7 +323,6 @@ if not mode:
341
  recipes.append(recipe)
342
  return recipes
343
 
344
-
345
  # get all saved files
346
  directory_path = 'data'
347
  recipes = load_saved_recipes_from_pickle(directory_path)
@@ -428,4 +409,4 @@ else:
428
  return StreamlitRenderer(df)
429
  # st.markdown("## :desktop_computer: DO YOUR OWN RESEARCH...")
430
  with st.expander("## :desktop_computer: LOOKING FOR SOMETHING ELSE..."):
431
- pygwalerapp(df).explorer()
 
 
 
 
 
 
 
1
  import random
2
+ import streamlit as st
3
+ import re, secrets, os, json
4
  import pandas as pd
5
  from huggingface_hub import login, InferenceClient
6
+ import pickle
7
  from sklearn.metrics.pairwise import cosine_similarity
8
+ import datetime
9
  import wordcloud
10
  import matplotlib.pyplot as plt
11
  from pygwalker.api.streamlit import StreamlitRenderer
 
27
  items_dict = pd.DataFrame.from_dict(pickle.load(file))
28
 
29
 
30
+ mode = st.toggle(label="MARTMAN")
31
 
32
  if 'ind' not in st.session_state:
33
  st.session_state.ind = []
 
67
 
68
 
69
  # Initialize the inference client for the Mixtral model
 
70
  if not mode:
71
  cook, saved = st.tabs(['COOK', 'SAVED'])
72
  with cook:
 
91
  st.session_state.exclusions = None
92
 
93
 
 
 
 
 
 
 
 
94
  def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
95
  if difficulty == "Quick & Easy":
96
  prompt = (
 
115
  )
116
  return prompt
117
 
 
118
  def generate_recipe(user_inputs):
119
  with st.spinner('Building the perfect recipe...'):
120
  prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'],
 
188
  st.session_state.recipe = response
189
  st.session_state.recipe_saved = False
190
 
 
191
  def clear_inputs():
192
  st.session_state.user_direction = None
193
  st.session_state.exclusions = None
 
195
  st.session_state.selected_difficulty = "Quick & Easy"
196
  st.session_state.recipe = None
197
 
 
198
  st.title("Let's get cooking")
199
  col1, col2 = st.columns(2)
200
  with col1:
 
263
 
264
  button_cols_submit = st.columns([1, 1, 4])
265
  with button_cols_submit[0]:
266
+ st.button(label='Submit', on_click=generate_recipe, kwargs=dict(user_inputs=user_inputs),
267
+ type="primary",
268
  use_container_width=True)
269
  with button_cols_submit[1]:
270
  st.button(label='Reset', on_click=clear_inputs, type="secondary", use_container_width=True)
271
  with button_cols_submit[2]:
272
  st.empty()
273
 
 
274
  def create_safe_filename(recipe_name):
275
  # format and generate random URL-safe text string
276
  safe_name = recipe_name.lower()
 
281
  safe_filename = f"{unique_token}_{safe_name}"
282
  return safe_filename
283
 
 
284
  def save_recipe():
285
  with st.spinner('WAIT SAVING YOUR DISH...'):
286
  filename = create_safe_filename(recipe["name"])
 
289
  pickle.dump(recipe, f)
290
  st.session_state.recipe_saved = True
291
 
 
292
  if st.session_state.recipe is not None:
293
  st.divider()
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
 
323
  recipes.append(recipe)
324
  return recipes
325
 
 
326
  # get all saved files
327
  directory_path = 'data'
328
  recipes = load_saved_recipes_from_pickle(directory_path)
 
409
  return StreamlitRenderer(df)
410
  # st.markdown("## :desktop_computer: DO YOUR OWN RESEARCH...")
411
  with st.expander("## :desktop_computer: LOOKING FOR SOMETHING ELSE..."):
412
+ pygwalerapp(df).explorer()