Upload 3 files
Browse files- app.py +31 -142
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,147 +1,36 @@
|
|
1 |
-
#import streamlit as st
|
2 |
-
#from PIL import Image
|
3 |
-
#from recipe_model import predict_dish, generate_recipe
|
4 |
-
|
5 |
-
#st.set_page_config(page_title="AI Recipe Chef", layout="centered", page_icon="π³")
|
6 |
-
#st.title("π¨βπ³ AI Recipe Chef")
|
7 |
-
#st.write("Upload any food image and get a real AI-generated recipe with filters.")
|
8 |
-
#st.markdown(
|
9 |
-
# "<h1 style='text-align: center; color: #F63366;'>π¨βπ³ AI Recipe Chef</h1>",
|
10 |
-
# unsafe_allow_html=True
|
11 |
-
#)
|
12 |
-
#st.markdown("<p style='text-align: center;'>Upload a food image and get a personalized recipe with filters!</p>", unsafe_allow_html=True)
|
13 |
-
#uploaded_image = st.file_uploader("Upload food image", type=["jpg", "jpeg", "png"])
|
14 |
-
#st.sidebar.title("πHistory")
|
15 |
-
#diet = st.selectbox("Dietary Preference", [
|
16 |
-
# "Any", "Vegetarian", "Non-Vegetarian", "Keto", "Gluten-Free", "Paleo"])
|
17 |
-
|
18 |
-
#cuisine = st.selectbox("Cuisine", ["Any","Indian", "Chinese", "Italian", "Mexican", "Meditarrean"])
|
19 |
-
#cook_time = st.selectbox("Cook Time", ["Any","<15 mins", "15-30 mins", ">30 mins","1 hour"])
|
20 |
-
|
21 |
-
#if uploaded_image:
|
22 |
-
# st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
23 |
-
# with st.spinner("Detecting dish..."):
|
24 |
-
# dish = predict_dish(uploaded_image)
|
25 |
-
# st.success(f"Detected Dish: {dish}")
|
26 |
-
|
27 |
-
# with st.spinner("Generating recipe..."):
|
28 |
-
# import time
|
29 |
-
# time.sleep(0.8)
|
30 |
-
# recipe = generate_recipe(dish, diet, cuisine, cook_time)
|
31 |
-
|
32 |
-
# st.subheader("π Ingredients & Instructions")
|
33 |
-
# st.markdown(recipe, unsafe_allow_html=True)
|
34 |
-
from __future__ import annotations
|
35 |
import streamlit as st
|
36 |
from PIL import Image
|
37 |
-
from
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
"
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
"cook_time": "<30 min",
|
69 |
-
"ingredients": [
|
70 |
-
"1 cup cooked rice",
|
71 |
-
"2 eggs",
|
72 |
-
"Soy sauce",
|
73 |
-
"Chopped spring onion",
|
74 |
-
"Salt & pepper",
|
75 |
-
],
|
76 |
-
"instructions": [
|
77 |
-
"Scramble eggs in a pan.",
|
78 |
-
"Add rice and soy sauce.",
|
79 |
-
"Mix well with veggies.",
|
80 |
-
"Garnish with spring onion.",
|
81 |
-
],
|
82 |
-
},
|
83 |
-
]
|
84 |
-
|
85 |
-
# ---------------- UI ----------------
|
86 |
-
def main() -> None:
|
87 |
-
|
88 |
-
st.set_page_config(page_title="AI Recipe Generator", page_icon="π³", layout="centered")
|
89 |
-
st.title("πΈπ½οΈ AI-Powered Recipe Generator")
|
90 |
-
|
91 |
-
uploaded = st.file_uploader("Upload your fridge / pantry photo", type=["jpg", "jpeg", "png"])
|
92 |
-
if uploaded:
|
93 |
-
img = Image.open(uploaded)
|
94 |
-
st.image(img, caption="Uploaded image", use_column_width=True)
|
95 |
-
|
96 |
-
st.subheader("Filters")
|
97 |
-
col1, col2, col3 = st.columns(3)
|
98 |
-
with col1:
|
99 |
-
diet = st.selectbox("Diet", ["Any", "Vegetarian", "Vegan", "Keto", "Pescatarian", "Gluten-Free"])
|
100 |
-
with col2:
|
101 |
-
cuisine = st.selectbox("Cuisine", ["Any", "Indian", "Italian", "Mexican", "Chinese", "Mediterranean"])
|
102 |
-
with col3:
|
103 |
-
cook_time = st.selectbox("Cook time", ["Any", "<15 min", "<30 min", "<45 min", "1 hour+"])
|
104 |
-
|
105 |
-
if st.button("Generate Recipes", type="primary"):
|
106 |
-
with st.spinner("Chef-bot is thinkingβ¦"):
|
107 |
-
recs = generate_recipes(img, {"diet": diet, "cuisine": cuisine, "cook_time": cook_time})
|
108 |
-
|
109 |
-
if not recs:
|
110 |
-
st.warning("No recipes found β try relaxing a filter.")
|
111 |
-
else:
|
112 |
-
st.success(f"{len(recs)} recipe{'s' if len(recs)>1 else ''} found!")
|
113 |
-
show_recipes(recs)
|
114 |
-
|
115 |
-
if st.session_state.get("favourites"):
|
116 |
-
st.divider()
|
117 |
-
st.subheader("β Saved favourites")
|
118 |
-
show_recipes(st.session_state["favourites"], favourite=True)
|
119 |
-
else:
|
120 |
-
st.info("π Upload an image to start.")
|
121 |
-
|
122 |
-
def show_recipes(recs: List[Dict], favourite: bool = False) -> None:
|
123 |
-
for i, r in enumerate(recs):
|
124 |
-
with st.expander(f"π½οΈ {r['title']}"):
|
125 |
-
c1, c2, c3 = st.columns([2, 1, 1])
|
126 |
-
with c1:
|
127 |
-
st.markdown(f"**Diet:** {r['diet']}")
|
128 |
-
st.markdown(f"**Cuisine:** {r['cuisine']}")
|
129 |
-
st.markdown(f"**Time:** {r['cook_time']}")
|
130 |
-
with c2:
|
131 |
-
rating = st.slider("Rate", 1, 5, 3, key=f"rating_{i}_{favourite}")
|
132 |
-
st.session_state.setdefault("ratings", {})[r["title"]] = rating
|
133 |
-
with c3:
|
134 |
-
fav_key = f"fav_{i}_{favourite}"
|
135 |
-
if st.checkbox("β€οΈ Save", key=fav_key):
|
136 |
-
st.session_state.setdefault("favourites", []).append(r)
|
137 |
-
|
138 |
-
st.markdown("**Ingredients**")
|
139 |
-
st.markdown("\n".join(f"- {ing}" for ing in r["ingredients"]))
|
140 |
-
st.markdown("**Instructions**")
|
141 |
-
st.markdown("\n".join(f"{j+1}. {step}" for j, step in enumerate(r["instructions"])))
|
142 |
-
|
143 |
-
if __name__ == "__main__":
|
144 |
-
main()
|
145 |
|
146 |
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
+
from recipe_model import predict_dish, generate_recipe
|
4 |
+
|
5 |
+
st.set_page_config(page_title="AI Recipe Chef", layout="centered", page_icon="π³")
|
6 |
+
st.title("π¨βπ³ AI Recipe Chef")
|
7 |
+
st.write("Upload any food image and get a real AI-generated recipe with filters.")
|
8 |
+
st.markdown(
|
9 |
+
"<h1 style='text-align: center; color: #F63366;'>π¨βπ³ AI Recipe Chef</h1>",
|
10 |
+
unsafe_allow_html=True
|
11 |
+
)
|
12 |
+
st.markdown("<p style='text-align: center;'>Upload a food image and get a personalized recipe with filters!</p>", unsafe_allow_html=True)
|
13 |
+
uploaded_image = st.file_uploader("Upload food image", type=["jpg", "jpeg", "png"])
|
14 |
+
st.sidebar.title("πHistory")
|
15 |
+
diet = st.selectbox("Dietary Preference", [
|
16 |
+
"Any", "Vegetarian", "Non-Vegetarian", "Keto", "Gluten-Free", "Paleo"])
|
17 |
+
|
18 |
+
cuisine = st.selectbox("Cuisine", ["Any","Indian", "Chinese", "Italian", "Mexican", "Meditarrean"])
|
19 |
+
cook_time = st.selectbox("Cook Time", ["Any","<15 mins", "15-30 mins", ">30 mins","1 hour"])
|
20 |
+
|
21 |
+
if uploaded_image:
|
22 |
+
st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
23 |
+
with st.spinner("Detecting dish..."):
|
24 |
+
dish = predict_dish(uploaded_image)
|
25 |
+
st.success(f"Detected Dish: {dish}")
|
26 |
+
|
27 |
+
with st.spinner("Generating recipe..."):
|
28 |
+
import time
|
29 |
+
time.sleep(0.8)
|
30 |
+
recipe = generate_recipe(dish, diet, cuisine, cook_time)
|
31 |
+
|
32 |
+
st.subheader("π Ingredients & Instructions")
|
33 |
+
st.markdown(recipe, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
|
36 |
|
requirements.txt
CHANGED
@@ -3,3 +3,4 @@ torch
|
|
3 |
torchvision
|
4 |
transformers
|
5 |
pillow
|
|
|
|
3 |
torchvision
|
4 |
transformers
|
5 |
pillow
|
6 |
+
requests
|