Skip to content

Commit f7ca6cc

Browse files
Merge pull request #2732 from avinashkranjan/deepsource-transform-e4cc2b37
format code with autopep8
2 parents d7ffe75 + 0e68b63 commit f7ca6cc

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

AI-Powered Recipe Generator/recipe_generator.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,16 @@
6767
}
6868

6969
# Function to preprocess the recipes
70+
71+
7072
def preprocess_recipe(recipe):
7173
stop_words = set(stopwords.words("english"))
7274
tokens = word_tokenize(recipe.lower())
7375
return [word for word in tokens if word.isalpha() and word not in stop_words]
7476

7577
# Function to generate a unique recipe
78+
79+
7680
def generate_recipe(ingredients, preferences=None):
7781
processed_ingredients = preprocess_recipe(ingredients)
7882

@@ -91,21 +95,29 @@ def generate_recipe(ingredients, preferences=None):
9195
# Function to get user ingredient substitutions
9296

9397
# Function to suggest similar recipes
98+
99+
94100
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)
96103
return similar_recipes
97104

98105
# Main function
106+
107+
99108
def main():
100109
print("AI-Powered Recipe Generator")
101110
print("Available Recipes:")
102111
for idx, recipe_name in enumerate(recipes.keys(), start=1):
103112
print(f"{idx}. {recipe_name}")
104113

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(",")
107118

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)
109121

110122
print("\nGenerated Recipe:")
111123
print(f"Recipe: {generated_recipe_name}")
@@ -114,12 +126,12 @@ def main():
114126
print(recipe_instructions[generated_recipe_name])
115127
print("Source Link:", source_link)
116128

117-
118129
similar_recipes = suggest_similar_recipes(generated_recipe_name)
119130
print("\nYou may also like these recipes:")
120131
for idx, recipe_name in enumerate(similar_recipes, start=1):
121132
print(f"{idx}. {recipe_name}")
122133

134+
123135
if __name__ == "__main__":
124136
nltk.download("punkt")
125137
nltk.download("stopwords")

0 commit comments

Comments
 (0)