67
67
}
68
68
69
69
# Function to preprocess the recipes
70
+
71
+
70
72
def preprocess_recipe (recipe ):
71
73
stop_words = set (stopwords .words ("english" ))
72
74
tokens = word_tokenize (recipe .lower ())
73
75
return [word for word in tokens if word .isalpha () and word not in stop_words ]
74
76
75
77
# Function to generate a unique recipe
78
+
79
+
76
80
def generate_recipe (ingredients , preferences = None ):
77
81
processed_ingredients = preprocess_recipe (ingredients )
78
82
@@ -91,21 +95,29 @@ def generate_recipe(ingredients, preferences=None):
91
95
# Function to get user ingredient substitutions
92
96
93
97
# Function to suggest similar recipes
98
+
99
+
94
100
def suggest_similar_recipes (generated_recipe_name ):
95
- similar_recipes = random .sample ([name for name in recipes .keys () if name != generated_recipe_name ], 2 )
101
+ similar_recipes = random .sample (
102
+ [name for name in recipes .keys () if name != generated_recipe_name ], 2 )
96
103
return similar_recipes
97
104
98
105
# Main function
106
+
107
+
99
108
def main ():
100
109
print ("AI-Powered Recipe Generator" )
101
110
print ("Available Recipes:" )
102
111
for idx , recipe_name in enumerate (recipes .keys (), start = 1 ):
103
112
print (f"{ idx } . { recipe_name } " )
104
113
105
- user_ingredients = input ("Enter the list of ingredients you have (comma-separated): " )
106
- user_preferences = input ("Enter your dietary preferences (comma-separated, or press Enter to skip): " ).split ("," )
114
+ user_ingredients = input (
115
+ "Enter the list of ingredients you have (comma-separated): " )
116
+ user_preferences = input (
117
+ "Enter your dietary preferences (comma-separated, or press Enter to skip): " ).split ("," )
107
118
108
- generated_recipe_name , source_link = generate_recipe (user_ingredients , user_preferences )
119
+ generated_recipe_name , source_link = generate_recipe (
120
+ user_ingredients , user_preferences )
109
121
110
122
print ("\n Generated Recipe:" )
111
123
print (f"Recipe: { generated_recipe_name } " )
@@ -114,12 +126,12 @@ def main():
114
126
print (recipe_instructions [generated_recipe_name ])
115
127
print ("Source Link:" , source_link )
116
128
117
-
118
129
similar_recipes = suggest_similar_recipes (generated_recipe_name )
119
130
print ("\n You may also like these recipes:" )
120
131
for idx , recipe_name in enumerate (similar_recipes , start = 1 ):
121
132
print (f"{ idx } . { recipe_name } " )
122
133
134
+
123
135
if __name__ == "__main__" :
124
136
nltk .download ("punkt" )
125
137
nltk .download ("stopwords" )
0 commit comments