Spaces:
Sleeping
Sleeping
Update app.py
Browse files1342 unmodified lines13431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941342 unmodified linessaved_count = 0total_ingredients = 0# Save all recipesfor title in recipe_generator.recent_titles:# Generate full reciperecipe_content = recipe_generator.generate_recipe(title, cost_per_meal, meals_per_week, postcode,preferences, people_count, meal_type, budget_preference)if recipe_content:# Set as current recipe and saverecipe_generator.current_recipe = {"title": title,"content": recipe_content,"cost_per_meal": cost_per_meal,"location": postcode if postcode else "UK","date": datetime.now().strftime("%Y-%m-%d %H:%M")}# Save reciperecipe_generator.save_current_recipe()saved_count += 1# Extract and add ingredientsingredients = shopping_list_manager.extract_ingredients_from_recipe(recipe_content)for ingredient in ingredients:category = shopping_list_manager.categorize_ingredient(ingredient)result = shopping_list_manager.add_item(ingredient, "", f"From: {title}", category)if "already in" not in result:total_ingredients += 1# Update saved recipes listchoices = []for recipe in recipe_generator.saved_recipes:title = recipe["title"]cost = recipe["cost_per_meal"]choice_text = f"{title} (£{cost}/meal)"choices.append(choice_text)count = len(recipe_generator.saved_recipes)count_text = f"**{count} recipe{'s' if count != 1 else ''} saved**"# Update shopping listshopping_choices, shopping_df = get_shopping_checkboxes()status_msg = f"🎉 **Success!** Saved {saved_count} recipes and added {total_ingredients} ingredients to your shopping list!"return (gr.update(value=status_msg),1342 unmodified lines1343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961342 unmodified linessaved_count = 0total_ingredients = 0skipped_ingredients = 0# Save all recipesfor i, title in enumerate(recipe_generator.recent_titles):try:# Generate full recipe using the indexrecipe_content = recipe_generator.generate_full_recipe(i, cost_per_meal, postcode, preferences,meals_per_week, people_count, meal_type, budget_preference)if recipe_content and "Error" not in recipe_content:# Now explicitly save the recipesave_result = recipe_generator.save_current_recipe()if "successfully" in save_result:saved_count += 1# Extract and add ingredientsingredients = shopping_list_manager.extract_ingredients_from_recipe(recipe_content)for ingredient in ingredients:category = shopping_list_manager.categorize_ingredient(ingredient)result = shopping_list_manager.add_item(ingredient, "", "From: {0}".format(title), category)if "already in" in result:skipped_ingredients += 1else:total_ingredients += 1except Exception as e:print("Error processing recipe {0}: {1}".format(title, str(e)))continue# Update saved recipes listchoices = []for recipe in recipe_generator.saved_recipes:recipe_title = recipe["title"]cost = recipe.get("cost_per_meal", cost_per_meal)choice_text = "{0} (£{1}/meal)".format(recipe_title, cost)choices.append(choice_text)count = len(recipe_generator.saved_recipes)count_text = "**{0} recipe{1} saved**".format(count, 's' if count != 1 else '')# Update shopping listshopping_choices, shopping_df = get_shopping_checkboxes()# Create success messagestatus_msg = "🎉 **Success!** Saved {0} recipes and added {1} ingredients to your shopping list!".format(saved_count, total_ingredients)if skipped_ingredients > 0:status_msg += " ({0} already in list)".format(skipped_ingredients)return (gr.update(value=status_msg),
app.py+34-32