Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
recipes_df.
|
|
|
|
|
|
|
|
|
|
| 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 ---
|