Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
from PIL import Image
|
3 |
import requests
|
4 |
import json
|
@@ -104,6 +105,9 @@ def main():
|
|
104 |
probs = outputs.logits.softmax(dim=1)
|
105 |
percentage = round(probs[0, label_num].item() * 100, 2)
|
106 |
|
|
|
|
|
|
|
107 |
st.write("The Predicted Classification is:")
|
108 |
|
109 |
if label_num==0:
|
@@ -134,14 +138,16 @@ def main():
|
|
134 |
st.write("You Selected **{}** For Diet and **{}** For Cuisine with Max".format(diet, cuisine), calories, "Calories For", ( "**Bread**" if label_num==0 else "**Dairy**" if label_num==1 else "**Dessert**" if label_num==2 else "**Egg**" if label_num==3 else "**Fried Food**" if label_num==4 else "**Fruit**" if label_num==5 else "**Meat**" if label_num==6 else "**Noodles**" if label_num==7 else "**Rice**" if label_num==8 else "**Seafood**" if label_num==9 else "**Soup**" if label_num==10 else "**Vegetable**"))
|
135 |
|
136 |
# Add code to fetch healthy recipe here (line #125-138)
|
137 |
-
|
138 |
st.image(img, width=260)
|
139 |
|
140 |
url = "https://alcksyjrmd.execute-api.us-east-2.amazonaws.com/default/nutrients_response"
|
141 |
|
142 |
-
|
|
|
|
|
143 |
|
144 |
-
params = {"f": category}
|
145 |
|
146 |
if diet != "All":
|
147 |
params["d"] = diet
|
@@ -149,14 +155,75 @@ def main():
|
|
149 |
if cuisine != "All":
|
150 |
params["c"] = cuisine
|
151 |
|
152 |
-
st.markdown("### Recommended Recipe:")
|
153 |
response = requests.get(url, params=params)
|
154 |
response_json = json.loads(response.content)
|
155 |
|
156 |
if len(response_json) == 0:
|
|
|
157 |
st.write("**No Recipe Found, please try another option from the dropdown menus.**")
|
158 |
else:
|
159 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
st.markdown("<hr style='text-align: center;'>", unsafe_allow_html=True)
|
162 |
st.markdown("<p style='text-align: center'><a href='https://github.com/Kaludii'>Github</a> | <a href='https://huggingface.co/Kaludi'>HuggingFace</a></p>", unsafe_allow_html=True)
|
|
|
1 |
import streamlit as st
|
2 |
+
import random
|
3 |
from PIL import Image
|
4 |
import requests
|
5 |
import json
|
|
|
105 |
probs = outputs.logits.softmax(dim=1)
|
106 |
percentage = round(probs[0, label_num].item() * 100, 2)
|
107 |
|
108 |
+
st.markdown("### Your Image:")
|
109 |
+
st.image(img, width=260)
|
110 |
+
|
111 |
st.write("The Predicted Classification is:")
|
112 |
|
113 |
if label_num==0:
|
|
|
138 |
st.write("You Selected **{}** For Diet and **{}** For Cuisine with Max".format(diet, cuisine), calories, "Calories For", ( "**Bread**" if label_num==0 else "**Dairy**" if label_num==1 else "**Dessert**" if label_num==2 else "**Egg**" if label_num==3 else "**Fried Food**" if label_num==4 else "**Fruit**" if label_num==5 else "**Meat**" if label_num==6 else "**Noodles**" if label_num==7 else "**Rice**" if label_num==8 else "**Seafood**" if label_num==9 else "**Soup**" if label_num==10 else "**Vegetable**"))
|
139 |
|
140 |
# Add code to fetch healthy recipe here (line #125-138)
|
141 |
+
st.markdown("### Your Image:")
|
142 |
st.image(img, width=260)
|
143 |
|
144 |
url = "https://alcksyjrmd.execute-api.us-east-2.amazonaws.com/default/nutrients_response"
|
145 |
|
146 |
+
max_calories = calories
|
147 |
+
|
148 |
+
category = ("Bread" if label_num==0 else "Dairy" if label_num==1 else "Dessert" if label_num==2 else "Egg" if label_num==3 else "Fried" if label_num==4 else "Fruit" if label_num==5 else "Meat" if label_num==6 else "Noodles" if label_num==7 else "Rice" if label_num==8 else "Seafood" if label_num==9 else "**Soup**" if label_num==10 else "Vegetable")
|
149 |
|
150 |
+
params = {"f": category, "Calories": max_calories}
|
151 |
|
152 |
if diet != "All":
|
153 |
params["d"] = diet
|
|
|
155 |
if cuisine != "All":
|
156 |
params["c"] = cuisine
|
157 |
|
|
|
158 |
response = requests.get(url, params=params)
|
159 |
response_json = json.loads(response.content)
|
160 |
|
161 |
if len(response_json) == 0:
|
162 |
+
st.markdown("### No Recipe Found:")
|
163 |
st.write("**No Recipe Found, please try another option from the dropdown menus.**")
|
164 |
else:
|
165 |
+
st.markdown("### Recommended Recipe:")
|
166 |
+
if len(response_json) > 1:
|
167 |
+
random_recipe = random.choice(response_json)
|
168 |
+
st.write("**Title:** ", random_recipe['Title'])
|
169 |
+
if random_recipe['Image Link'].endswith(".jpg") or random_recipe['Image Link'].endswith(".jpeg") or random_recipe['Image Link'].endswith(".png"):
|
170 |
+
st.image(random_recipe['Image Link'], width=300)
|
171 |
+
else:
|
172 |
+
st.write("**Image Link:** ", random_recipe['Image Link'])
|
173 |
+
st.write("**Rating:** ", random_recipe['Rating'])
|
174 |
+
st.write("**Description:** ", random_recipe['Description'])
|
175 |
+
st.write("**Ingredients:** ", random_recipe['Ingredients'])
|
176 |
+
st.write("**Recipe Facts:** ", random_recipe['Recipe Facts'])
|
177 |
+
st.write("**Directions:** ", random_recipe['Directions'])
|
178 |
+
st.write("**Nutrition Facts:** ", random_recipe['Nutrition Facts'])
|
179 |
+
st.write("**Number of Servings:** ", random_recipe['Number of Servings'])
|
180 |
+
st.write("**Calories:** ", random_recipe['Calories'])
|
181 |
+
st.write("**Total Fat:** ", random_recipe['Total Fat'])
|
182 |
+
st.write("**Saturated Fat:** ", random_recipe['Saturated Fat'])
|
183 |
+
st.write("**Cholesterol:** ", random_recipe['Cholesterol'])
|
184 |
+
st.write("**Sodium:** ", random_recipe['Sodium'])
|
185 |
+
st.write("**Total Carbohydrate:** ", random_recipe['Total Carbohydrate'])
|
186 |
+
st.write("**Dietary Fiber:** ", random_recipe['Dietary Fiber'])
|
187 |
+
st.write("**Total Sugars:** ", random_recipe['Total Sugars'])
|
188 |
+
st.write("**Protein:** ", random_recipe['Protein'])
|
189 |
+
st.write("**Vitamin C:** ", random_recipe['Vitamin C'])
|
190 |
+
st.write("**Calcium:** ", random_recipe['Calcium'])
|
191 |
+
st.write("**Iron:** ", random_recipe['Iron'])
|
192 |
+
st.write("**Potassium:** ", random_recipe['Potassium'])
|
193 |
+
st.write("**Tags:** ", random_recipe['Tags'])
|
194 |
+
st.write("**Recipe URL:** ", random_recipe['Recipe URLs'])
|
195 |
+
st.markdown("### JSON:")
|
196 |
+
st.write(response_json)
|
197 |
+
else:
|
198 |
+
st.write("**Title:** ", response_json[0]['Title'])
|
199 |
+
if response_json[0]['Image Link'].endswith(".jpg") or response_json[0]['Image Link'].endswith(".jpeg") or response_json[0]['Image Link'].endswith(".png"):
|
200 |
+
st.image(response_json[0]['Image Link'], width=300)
|
201 |
+
else:
|
202 |
+
st.write("**Image Link:** ", response_json[0]['Image Link'])
|
203 |
+
st.write("**Rating:** ", response_json[0]['Rating'])
|
204 |
+
st.write("**Description:** ", response_json[0]['Description'])
|
205 |
+
st.write("**Ingredients:** ", response_json[0]['Ingredients'])
|
206 |
+
st.write("**Recipe Facts:** ", response_json[0]['Recipe Facts'])
|
207 |
+
st.write("**Directions:** ", response_json[0]['Directions'])
|
208 |
+
st.write("**Nutrition Facts:** ", response_json[0]['Nutrition Facts'])
|
209 |
+
st.write("**Number of Servings:** ", response_json[0]['Number of Servings'])
|
210 |
+
st.write("**Calories:** ", response_json[0]['Calories'])
|
211 |
+
st.write("**Total Fat:** ", response_json[0]['Total Fat'])
|
212 |
+
st.write("**Saturated Fat:** ", response_json[0]['Saturated Fat'])
|
213 |
+
st.write("**Cholesterol:** ", response_json[0]['Cholesterol'])
|
214 |
+
st.write("**Sodium:** ", response_json[0]['Sodium'])
|
215 |
+
st.write("**Total Carbohydrate:** ", response_json[0]['Total Carbohydrate'])
|
216 |
+
st.write("**Dietary Fiber:** ", response_json[0]['Dietary Fiber'])
|
217 |
+
st.write("**Total Sugars:** ", response_json[0]['Total Sugars'])
|
218 |
+
st.write("**Protein:** ", response_json[0]['Protein'])
|
219 |
+
st.write("**Vitamin C:** ", response_json[0]['Vitamin C'])
|
220 |
+
st.write("**Calcium:** ", response_json[0]['Calcium'])
|
221 |
+
st.write("**Iron:** ", response_json[0]['Iron'])
|
222 |
+
st.write("**Potassium:** ", response_json[0]['Potassium'])
|
223 |
+
st.write("**Tags:** ", response_json[0]['Tags'])
|
224 |
+
st.write("**Recipe URL:** ", response_json[0]['Recipe URLs'])
|
225 |
+
st.markdown("### JSON:")
|
226 |
+
st.write(response_json)
|
227 |
|
228 |
st.markdown("<hr style='text-align: center;'>", unsafe_allow_html=True)
|
229 |
st.markdown("<p style='text-align: center'><a href='https://github.com/Kaludii'>Github</a> | <a href='https://huggingface.co/Kaludi'>HuggingFace</a></p>", unsafe_allow_html=True)
|