krisha06 commited on
Commit
697474f
·
verified ·
1 Parent(s): 62b5056

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -9,21 +9,37 @@ from io import BytesIO
9
  # --- 1. Load Recipes Dataset ---
10
  @st.cache_data
11
  def load_recipes():
12
- dataset = load_dataset("recipes.csv", split="train")
13
- recipes_df = dataset.to_pandas()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- # Rename columns to match expected ones
16
- recipes_df = recipes_df.rename(columns={"recipe_name": "title", "directions": "instructions"})
17
 
18
- # Keep only required columns
19
- recipes_df = recipes_df[['title', 'ingredients', 'instructions']]
20
- recipes_df.fillna("", inplace=True)
 
 
 
21
 
22
- # Clean the ingredients column
23
- recipes_df["ingredients"] = recipes_df["ingredients"].str.lower().str.replace(r'[^\w\s]', '', regex=True)
24
- recipes_df["combined_text"] = recipes_df["title"] + " " + recipes_df["ingredients"]
25
-
26
- return recipes_df
27
 
28
 
29
  # --- 2. Setup SentenceTransformer Model for Embeddings ---
 
9
  # --- 1. Load Recipes Dataset ---
10
  @st.cache_data
11
  def load_recipes():
12
+ try:
13
+ # Load CSV using Pandas instead of Hugging Face dataset loader
14
+ recipes_df = pd.read_csv("recipes.csv")
15
+
16
+ # Rename columns to match expected names
17
+ recipes_df = recipes_df.rename(columns={"recipe_name": "title", "directions": "instructions"})
18
+
19
+ # Keep only necessary columns
20
+ recipes_df = recipes_df[['title', 'ingredients', 'instructions']]
21
+ recipes_df.fillna("", inplace=True)
22
+
23
+ # Clean ingredients text
24
+ recipes_df["ingredients"] = recipes_df["ingredients"].str.lower().str.replace(r'[^\w\s]', '', regex=True)
25
+ recipes_df["combined_text"] = recipes_df["title"] + " " + recipes_df["ingredients"]
26
+
27
+ return recipes_df
28
+
29
+ except Exception as e:
30
+ st.error(f"⚠️ Error loading recipes: {e}")
31
+ return pd.DataFrame() # Return empty DataFrame in case of failure
32
 
33
+ # Load the recipes before using them
34
+ recipes_df = load_recipes()
35
 
36
+ # Ensure `recipes_df` is not empty before iterating over it
37
+ if not recipes_df.empty:
38
+ for index, row in recipes_df.iterrows():
39
+ print(row) # Replace with actual processing logic
40
+ else:
41
+ st.warning("⚠️ No recipes found. Please check the CSV file.")
42
 
 
 
 
 
 
43
 
44
 
45
  # --- 2. Setup SentenceTransformer Model for Embeddings ---