-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipes_recommendation.py
56 lines (43 loc) · 1.95 KB
/
recipes_recommendation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import streamlit as st
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
# For AI model (replace with your chosen model)
import tensorflow as tf
# Replace with your recipe data
recipes = pd.read_csv("recipes.csv")
def recommend_recipes(user_preferences, available_ingredients):
# Preprocess user inputs and recipe data
# ...
# Create TF-IDF vectors
tfidf_vectorizer = TfidfVectorizer(stop_words='english')
tfidf_matrix = tfidf_vectorizer.fit_transform(recipes['ingredients'])
# Calculate cosine similarity
cosine_similarities = cosine_similarity(tfidf_matrix)
# Find the most similar recipes based on user inputs
# ...
return recommended_recipes
def main():
st.title("AI Recipe Recommender")
# User inputs
dietary_restrictions = st.multiselect("Dietary Restrictions:", ["Vegetarian", "Vegan", "Gluten-free", "Dairy-free"])
cuisine = st.selectbox("Cuisine:", ["Any", "Italian", "Mexican", "Indian", "Chinese"])
ingredients = st.text_input("Available Ingredients (comma-separated):")
allergies = st.text_input("Allergies (comma-separated):")
if st.button("Recommend Recipes"):
user_preferences = {
"dietary_restrictions": dietary_restrictions,
"cuisine": cuisine,
"ingredients": ingredients.split(","),
"allergies": allergies.split(",")
}
recommended_recipes = recommend_recipes(user_preferences, ingredients.split(","))
# Display recommended recipes with details and potential substitutions
for recipe in recommended_recipes:
st.subheader(recipe['title'])
st.write(recipe['description'])
# ... display ingredients, instructions, etc.
st.write("Potential Substitutions:")
# ... display potential substitutions based on user preferences and allergies
if __name__ == "__main__":
main()