Kaludi commited on
Commit
828846a
1 Parent(s): 939b30c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +240 -67
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import random
 
3
  from PIL import Image
4
  import requests
5
  import json
@@ -83,7 +84,7 @@ def main():
83
  cuisine = st.selectbox('Cuisine', cuisine_options)
84
 
85
  # Slider for Calories
86
- calories = st.slider("Select Max Calories (Per Serving)", 50, 2000)
87
 
88
  # print the calories
89
  st.write("Selected: **{}** Max Calories.".format(calories))
@@ -140,17 +141,11 @@ def main():
140
 
141
  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**"))
142
 
143
- # Add code to fetch healthy recipe here (line #125-138)
144
- st.markdown("### Your Image:")
145
- st.image(img, width=260)
146
-
147
  url = "https://alcksyjrmd.execute-api.us-east-2.amazonaws.com/default/nutrients_response"
148
 
149
- max_calories = calories
150
-
151
  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")
152
 
153
- params = {"f": category, "Calories": max_calories}
154
 
155
  if diet != "All":
156
  params["d"] = diet
@@ -161,13 +156,19 @@ def main():
161
  response = requests.get(url, params=params)
162
  response_json = json.loads(response.content)
163
 
 
 
 
 
 
164
  if len(response_json) == 0:
165
  st.markdown("### No Recipe Found:")
166
- st.write("**No Recipe Found, please try another option from the dropdown menus.**")
167
  else:
168
  st.markdown("### Recommended Recipe:")
169
  if len(response_json) > 1:
170
  random_recipe = random.choice(response_json)
 
171
  st.write("**Title:** ", random_recipe['Title'])
172
  if random_recipe['Image Link'].endswith(".jpg") or random_recipe['Image Link'].endswith(".jpeg") or random_recipe['Image Link'].endswith(".png"):
173
  st.image(random_recipe['Image Link'], width=300)
@@ -178,38 +179,124 @@ def main():
178
  st.write("**Description:** ", random_recipe['Description'])
179
  st.write("**Ingredients:** ", random_recipe['Ingredients'])
180
  st.write("**Recipe Facts:** ", random_recipe['Recipe Facts'])
181
- st.write("**Directions:** ", random_recipe['Directions'])
182
- st.write("**Nutrition Facts:** ", random_recipe['Nutrition Facts'])
183
- st.write("**Number of Servings:** ", random_recipe['Number of Servings'])
184
- st.write("**Calories:** ", random_recipe['Calories'])
185
- st.write("**Total Fat:** ", random_recipe['Total Fat'])
186
- st.write("**Saturated Fat:** ", random_recipe['Saturated Fat'])
187
- st.write("**Cholesterol:** ", random_recipe['Cholesterol'])
188
- st.write("**Sodium:** ", random_recipe['Sodium'])
189
- st.write("**Total Carbohydrate:** ", random_recipe['Total Carbohydrate'])
190
- st.write("**Dietary Fiber:** ", random_recipe['Dietary Fiber'])
191
- st.write("**Total Sugars:** ", random_recipe['Total Sugars'])
192
- st.write("**Protein:** ", random_recipe['Protein'])
193
- st.write("**Vitamin C:** ", random_recipe['Vitamin C'])
194
- st.write("**Calcium:** ", random_recipe['Calcium'])
195
- st.write("**Iron:** ", random_recipe['Iron'])
196
- st.write("**Potassium:** ", random_recipe['Potassium'])
197
- st.write("**Tags:** ", random_recipe['Tags'])
198
- st.write("**Recipe URL:** ", random_recipe['Recipe URLs'])
199
- # extract only numeric values
200
- values = [float(re.sub(r'[^\d.]+', '', random_recipe['Total Fat'])),
201
- float(re.sub(r'[^\d.]+', '', random_recipe['Saturated Fat'])),
202
- float(re.sub(r'[^\d.]+', '', random_recipe['Cholesterol'])),
203
- float(re.sub(r'[^\d.]+', '', random_recipe['Sodium'])),
204
- float(re.sub(r'[^\d.]+', '', random_recipe['Total Carbohydrate'])),
205
- float(re.sub(r'[^\d.]+', '', random_recipe['Dietary Fiber'])),
206
- float(re.sub(r'[^\d.]+', '', random_recipe['Total Sugars'])),
207
- float(re.sub(r'[^\d.]+', '', random_recipe['Protein']))]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  # create pie chart
209
- labels = ['Total Fat', 'Saturated Fat', 'Cholesterol', 'Sodium', 'Total Carbohydrate', 'Dietary Fiber', 'Total Sugars', 'Protein']
210
  fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
211
- st.markdown("### Macronutrients Pie Chart ;)")
212
  st.plotly_chart(fig)
 
 
213
  st.markdown("### JSON:")
214
  st.write(response_json)
215
  else:
@@ -224,38 +311,124 @@ def main():
224
  st.write("**Description:** ", response_json[0]['Description'])
225
  st.write("**Ingredients:** ", response_json[0]['Ingredients'])
226
  st.write("**Recipe Facts:** ", response_json[0]['Recipe Facts'])
227
- st.write("**Directions:** ", response_json[0]['Directions'])
228
- st.write("**Nutrition Facts:** ", response_json[0]['Nutrition Facts'])
229
- st.write("**Number of Servings:** ", response_json[0]['Number of Servings'])
230
- st.write("**Calories:** ", response_json[0]['Calories'])
231
- st.write("**Total Fat:** ", response_json[0]['Total Fat'])
232
- st.write("**Saturated Fat:** ", response_json[0]['Saturated Fat'])
233
- st.write("**Cholesterol:** ", response_json[0]['Cholesterol'])
234
- st.write("**Sodium:** ", response_json[0]['Sodium'])
235
- st.write("**Total Carbohydrate:** ", response_json[0]['Total Carbohydrate'])
236
- st.write("**Dietary Fiber:** ", response_json[0]['Dietary Fiber'])
237
- st.write("**Total Sugars:** ", response_json[0]['Total Sugars'])
238
- st.write("**Protein:** ", response_json[0]['Protein'])
239
- st.write("**Vitamin C:** ", response_json[0]['Vitamin C'])
240
- st.write("**Calcium:** ", response_json[0]['Calcium'])
241
- st.write("**Iron:** ", response_json[0]['Iron'])
242
- st.write("**Potassium:** ", response_json[0]['Potassium'])
243
- st.write("**Tags:** ", response_json[0]['Tags'])
244
- st.write("**Recipe URL:** ", response_json[0]['Recipe URLs'])
245
- # extract only numeric values
246
- values = [float(re.sub(r'[^\d.]+', '', response_json[0]['Total Fat'])),
247
- float(re.sub(r'[^\d.]+', '', response_json[0]['Saturated Fat'])),
248
- float(re.sub(r'[^\d.]+', '', response_json[0]['Cholesterol'])),
249
- float(re.sub(r'[^\d.]+', '', response_json[0]['Sodium'])),
250
- float(re.sub(r'[^\d.]+', '', response_json[0]['Total Carbohydrate'])),
251
- float(re.sub(r'[^\d.]+', '', response_json[0]['Dietary Fiber'])),
252
- float(re.sub(r'[^\d.]+', '', response_json[0]['Total Sugars'])),
253
- float(re.sub(r'[^\d.]+', '', response_json[0]['Protein']))]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  # create pie chart
255
- labels = ['Total Fat', 'Saturated Fat', 'Cholesterol', 'Sodium', 'Total Carbohydrate', 'Dietary Fiber', 'Total Sugars', 'Protein']
256
  fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
257
- st.markdown("### Macronutrients Pie Chart ;)")
258
  st.plotly_chart(fig)
 
 
259
  st.markdown("### JSON:")
260
  st.write(response_json)
261
 
 
1
  import streamlit as st
2
  import random
3
+ import pandas as pd
4
  from PIL import Image
5
  import requests
6
  import json
 
84
  cuisine = st.selectbox('Cuisine', cuisine_options)
85
 
86
  # Slider for Calories
87
+ calories = st.slider("Select Max Calories (Per Serving)", 25, 1000, 500)
88
 
89
  # print the calories
90
  st.write("Selected: **{}** Max Calories.".format(calories))
 
141
 
142
  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**"))
143
 
 
 
 
 
144
  url = "https://alcksyjrmd.execute-api.us-east-2.amazonaws.com/default/nutrients_response"
145
 
 
 
146
  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")
147
 
148
+ params = {"f": category, "k": str(calories)}
149
 
150
  if diet != "All":
151
  params["d"] = diet
 
156
  response = requests.get(url, params=params)
157
  response_json = json.loads(response.content)
158
 
159
+ # Convert response_json to a list
160
+ response_json = list(response_json)
161
+
162
+
163
+
164
  if len(response_json) == 0:
165
  st.markdown("### No Recipe Found:")
166
+ st.write("**No recipes found. Please adjust your search criteria.**")
167
  else:
168
  st.markdown("### Recommended Recipe:")
169
  if len(response_json) > 1:
170
  random_recipe = random.choice(response_json)
171
+ nutrition_facts = random_recipe['Nutrition Facts']
172
  st.write("**Title:** ", random_recipe['Title'])
173
  if random_recipe['Image Link'].endswith(".jpg") or random_recipe['Image Link'].endswith(".jpeg") or random_recipe['Image Link'].endswith(".png"):
174
  st.image(random_recipe['Image Link'], width=300)
 
179
  st.write("**Description:** ", random_recipe['Description'])
180
  st.write("**Ingredients:** ", random_recipe['Ingredients'])
181
  st.write("**Recipe Facts:** ", random_recipe['Recipe Facts'])
182
+ st.write("**Directions:** ", random_recipe['Directions'])
183
+ nutrition_html = """
184
+ <div id="nutrition-info_6-0" class="comp nutrition-info">
185
+ <table class="nutrition-info__table">
186
+ <thead>
187
+ <tr>
188
+ <th class="nutrition-info__heading" colspan="2">Nutrition Facts <span class="nutrition-info__heading-aside">(per serving)</span></th>
189
+ </tr>
190
+ <tr>
191
+ <th class="nutrition-info__heading" colspan="2">Number of Servings: <span class="nutrition-info__heading-aside">{servings}</span></th>
192
+ </tr>
193
+ </thead>
194
+ <tbody class="nutrition-info__table--body">
195
+ <tr class="nutrition-info__table--row">
196
+ <td class="nutrition-info__table--cell">Calories</td>
197
+ <td class="nutrition-info__table--cell">{calories}</td>
198
+ </tr>
199
+ <tr class="nutrition-info__table--row">
200
+ <td class="nutrition-info__table--cell">Total Fat</td>
201
+ <td class="nutrition-info__table--cell">{total_fat}</td>
202
+ </tr>
203
+ <tr class="nutrition-info__table--row">
204
+ <td class="nutrition-info__table--cell">Saturated Fat</td>
205
+ <td class="nutrition-info__table--cell">{saturated_fat}</td>
206
+ </tr>
207
+ <tr class="nutrition-info__table--row">
208
+ <td class="nutrition-info__table--cell">Cholesterol</td>
209
+ <td class="nutrition-info__table--cell">{cholesterol}</td>
210
+ </tr>
211
+ <tr class="nutrition-info__table--row">
212
+ <td class="nutrition-info__table--cell">Sodium</td>
213
+ <td class="nutrition-info__table--cell">{sodium}</td>
214
+ </tr>
215
+ <tr class="nutrition-info__table--row">
216
+ <td class="nutrition-info__table--cell">Total Carbohydrate</td>
217
+ <td class="nutrition-info__table--cell">{total_carbohydrate}</td>
218
+ </tr>
219
+ <tr class="nutrition-info__table--row">
220
+ <td class="nutrition-info__table--cell">Dietary Fiber</td>
221
+ <td class="nutrition-info__table--cell">{dietary_fiber}</td>
222
+ </tr>
223
+ <tr class="nutrition-info__table--row">
224
+ <td class="nutrition-info__table--cell">Total Sugars</td>
225
+ <td class="nutrition-info__table--cell">{total_sugars}</td>
226
+ </tr>
227
+ <tr class="nutrition-info__table--row">
228
+ <td class="nutrition-info__table--cell">Protein</td>
229
+ <td class="nutrition-info__table--cell">{protein}</td>
230
+ </tr>
231
+ <tr class="nutrition-info__table--row">
232
+ <td class="nutrition-info__table--cell">Vitamin C</td>
233
+ <td class="nutrition-info__table--cell">{vitc}</td>
234
+ </tr>
235
+ <tr class="nutrition-info__table--row">
236
+ <td class="nutrition-info__table--cell">Calcium</td>
237
+ <td class="nutrition-info__table--cell">{calc}</td>
238
+ </tr>
239
+ <tr class="nutrition-info__table--row">
240
+ <td class="nutrition-info__table--cell">Iron</td>
241
+ <td class="nutrition-info__table--cell">{iron}</td>
242
+ </tr>
243
+ <tr class="nutrition-info__table--row">
244
+ <td class="nutrition-info__table--cell">Potassium</td>
245
+ <td class="nutrition-info__table--cell">{pota}</td>
246
+ </tr>
247
+ </tbody>
248
+ </table>
249
+ </div>
250
+ """
251
+ # Use the nutrition HTML and format it with the values
252
+ formatted_html = nutrition_html.format(
253
+ calories=random_recipe['Calories'],
254
+ total_fat=random_recipe['Total Fat'],
255
+ saturated_fat=random_recipe['Saturated Fat'],
256
+ cholesterol=random_recipe['Cholesterol'],
257
+ sodium=random_recipe['Sodium'],
258
+ total_carbohydrate=random_recipe['Total Carbohydrate'],
259
+ dietary_fiber=random_recipe['Dietary Fiber'],
260
+ total_sugars=random_recipe['Total Sugars'],
261
+ servings=random_recipe['Number of Servings'],
262
+ vitc=random_recipe['Vitamin C'],
263
+ calc=random_recipe['Calcium'],
264
+ iron=random_recipe['Iron'],
265
+ pota=random_recipe['Potassium'],
266
+ protein=random_recipe['Protein']
267
+ )
268
+
269
+ # Define a function to apply the CSS styles to the table cells
270
+ def format_table(val):
271
+ return f"background-color: #133350; color: #fff; border: 1px solid #ddd; border-radius: .25rem; padding: .625rem .625rem 0; font-family: Helvetica; font-size: 1rem;"
272
+
273
+ with st.container():
274
+ # Add the nutrition table to the Streamlit app
275
+ st.write("<h2 style='text-align:left;'>Nutrition Facts</h2>", unsafe_allow_html=True)
276
+ st.write(f"<div style='max-height:none; overflow:auto'>{formatted_html}</div>", unsafe_allow_html=True)
277
+ st.write("<p style='text-align:left;'>*The % Daily Value (DV) tells you how much a nutrient in a food serving contributes to a daily diet. 2,000 calories a day is used for general nutrition advice.</p>", unsafe_allow_html=True)
278
+ # extract only numeric values and convert mg to g
279
+ values = [
280
+ float(re.sub(r'[^\d.]+', '', random_recipe['Total Fat'])),
281
+ float(re.sub(r'[^\d.]+', '', random_recipe['Saturated Fat'])),
282
+ float(re.sub(r'[^\d.]+', '', random_recipe['Cholesterol'])) / 1000,
283
+ float(re.sub(r'[^\d.]+', '', random_recipe['Sodium'])) / 1000,
284
+ float(re.sub(r'[^\d.]+', '', random_recipe['Total Carbohydrate'])),
285
+ float(re.sub(r'[^\d.]+', '', random_recipe['Dietary Fiber'])),
286
+ float(re.sub(r'[^\d.]+', '', random_recipe['Total Sugars'])),
287
+ float(re.sub(r'[^\d.]+', '', random_recipe['Protein'])),
288
+ float(re.sub(r'[^\d.]+', '', random_recipe['Vitamin C'])) / 1000,
289
+ float(re.sub(r'[^\d.]+', '', random_recipe['Calcium'])) / 1000,
290
+ float(re.sub(r'[^\d.]+', '', random_recipe['Iron'])) / 1000,
291
+ float(re.sub(r'[^\d.]+', '', random_recipe['Potassium'])) / 1000
292
+ ]
293
  # create pie chart
294
+ labels = ['Total Fat', 'Saturated Fat', 'Cholesterol', 'Sodium', 'Total Carbohydrate', 'Dietary Fiber', 'Total Sugars', 'Protein', 'Vitamin C', 'Calcium', 'Iron', 'Potassium']
295
  fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
296
+ st.markdown("### Macronutrients Pie Chart ;) (In Grams)")
297
  st.plotly_chart(fig)
298
+ st.write("**Tags:** ", random_recipe['Tags'])
299
+ st.write("**Recipe URL:** ", random_recipe['Recipe URLs'])
300
  st.markdown("### JSON:")
301
  st.write(response_json)
302
  else:
 
311
  st.write("**Description:** ", response_json[0]['Description'])
312
  st.write("**Ingredients:** ", response_json[0]['Ingredients'])
313
  st.write("**Recipe Facts:** ", response_json[0]['Recipe Facts'])
314
+ st.write("**Directions:** ", random_recipe['Directions'])
315
+ nutrition_html = """
316
+ <div id="nutrition-info_6-0" class="comp nutrition-info">
317
+ <table class="nutrition-info__table">
318
+ <thead>
319
+ <tr>
320
+ <th class="nutrition-info__heading" colspan="2">Nutrition Facts <span class="nutrition-info__heading-aside">(per serving)</span></th>
321
+ </tr>
322
+ <tr>
323
+ <th class="nutrition-info__heading" colspan="2">Number of Servings: <span class="nutrition-info__heading-aside">{servings}</span></th>
324
+ </tr>
325
+ </thead>
326
+ <tbody class="nutrition-info__table--body">
327
+ <tr class="nutrition-info__table--row">
328
+ <td class="nutrition-info__table--cell">Calories</td>
329
+ <td class="nutrition-info__table--cell">{calories}</td>
330
+ </tr>
331
+ <tr class="nutrition-info__table--row">
332
+ <td class="nutrition-info__table--cell">Total Fat</td>
333
+ <td class="nutrition-info__table--cell">{total_fat}</td>
334
+ </tr>
335
+ <tr class="nutrition-info__table--row">
336
+ <td class="nutrition-info__table--cell">Saturated Fat</td>
337
+ <td class="nutrition-info__table--cell">{saturated_fat}</td>
338
+ </tr>
339
+ <tr class="nutrition-info__table--row">
340
+ <td class="nutrition-info__table--cell">Cholesterol</td>
341
+ <td class="nutrition-info__table--cell">{cholesterol}</td>
342
+ </tr>
343
+ <tr class="nutrition-info__table--row">
344
+ <td class="nutrition-info__table--cell">Sodium</td>
345
+ <td class="nutrition-info__table--cell">{sodium}</td>
346
+ </tr>
347
+ <tr class="nutrition-info__table--row">
348
+ <td class="nutrition-info__table--cell">Total Carbohydrate</td>
349
+ <td class="nutrition-info__table--cell">{total_carbohydrate}</td>
350
+ </tr>
351
+ <tr class="nutrition-info__table--row">
352
+ <td class="nutrition-info__table--cell">Dietary Fiber</td>
353
+ <td class="nutrition-info__table--cell">{dietary_fiber}</td>
354
+ </tr>
355
+ <tr class="nutrition-info__table--row">
356
+ <td class="nutrition-info__table--cell">Total Sugars</td>
357
+ <td class="nutrition-info__table--cell">{total_sugars}</td>
358
+ </tr>
359
+ <tr class="nutrition-info__table--row">
360
+ <td class="nutrition-info__table--cell">Protein</td>
361
+ <td class="nutrition-info__table--cell">{protein}</td>
362
+ </tr>
363
+ <tr class="nutrition-info__table--row">
364
+ <td class="nutrition-info__table--cell">Vitamin C</td>
365
+ <td class="nutrition-info__table--cell">{vitc}</td>
366
+ </tr>
367
+ <tr class="nutrition-info__table--row">
368
+ <td class="nutrition-info__table--cell">Calcium</td>
369
+ <td class="nutrition-info__table--cell">{calc}</td>
370
+ </tr>
371
+ <tr class="nutrition-info__table--row">
372
+ <td class="nutrition-info__table--cell">Iron</td>
373
+ <td class="nutrition-info__table--cell">{iron}</td>
374
+ </tr>
375
+ <tr class="nutrition-info__table--row">
376
+ <td class="nutrition-info__table--cell">Potassium</td>
377
+ <td class="nutrition-info__table--cell">{pota}</td>
378
+ </tr>
379
+ </tbody>
380
+ </table>
381
+ </div>
382
+ """
383
+ # Use the nutrition HTML and format it with the values
384
+ formatted_html = nutrition_html.format(
385
+ calories=random_recipe['Calories'],
386
+ total_fat=random_recipe['Total Fat'],
387
+ saturated_fat=random_recipe['Saturated Fat'],
388
+ cholesterol=random_recipe['Cholesterol'],
389
+ sodium=random_recipe['Sodium'],
390
+ total_carbohydrate=random_recipe['Total Carbohydrate'],
391
+ dietary_fiber=random_recipe['Dietary Fiber'],
392
+ total_sugars=random_recipe['Total Sugars'],
393
+ servings=random_recipe['Number of Servings'],
394
+ vitc=random_recipe['Vitamin C'],
395
+ calc=random_recipe['Calcium'],
396
+ iron=random_recipe['Iron'],
397
+ pota=random_recipe['Potassium'],
398
+ protein=random_recipe['Protein']
399
+ )
400
+
401
+ # Define a function to apply the CSS styles to the table cells
402
+ def format_table(val):
403
+ return f"background-color: #133350; color: #fff; border: 1px solid #ddd; border-radius: .25rem; padding: .625rem .625rem 0; font-family: Helvetica; font-size: 1rem;"
404
+
405
+ with st.container():
406
+ # Add the nutrition table to the Streamlit app
407
+ st.write("<h2 style='text-align:left;'>Nutrition Facts</h2>", unsafe_allow_html=True)
408
+ st.write(f"<div style='max-height:none; overflow:auto'>{formatted_html}</div>", unsafe_allow_html=True)
409
+ st.write("<p style='text-align:left;'>*The % Daily Value (DV) tells you how much a nutrient in a food serving contributes to a daily diet. 2,000 calories a day is used for general nutrition advice.</p>", unsafe_allow_html=True)
410
+ # extract only numeric values and convert mg to g
411
+ values = [
412
+ float(re.sub(r'[^\d.]+', '', random_recipe['Total Fat'])),
413
+ float(re.sub(r'[^\d.]+', '', random_recipe['Saturated Fat'])),
414
+ float(re.sub(r'[^\d.]+', '', random_recipe['Cholesterol'])) / 1000,
415
+ float(re.sub(r'[^\d.]+', '', random_recipe['Sodium'])) / 1000,
416
+ float(re.sub(r'[^\d.]+', '', random_recipe['Total Carbohydrate'])),
417
+ float(re.sub(r'[^\d.]+', '', random_recipe['Dietary Fiber'])),
418
+ float(re.sub(r'[^\d.]+', '', random_recipe['Total Sugars'])),
419
+ float(re.sub(r'[^\d.]+', '', random_recipe['Protein'])),
420
+ float(re.sub(r'[^\d.]+', '', random_recipe['Vitamin C'])) / 1000,
421
+ float(re.sub(r'[^\d.]+', '', random_recipe['Calcium'])) / 1000,
422
+ float(re.sub(r'[^\d.]+', '', random_recipe['Iron'])) / 1000,
423
+ float(re.sub(r'[^\d.]+', '', random_recipe['Potassium'])) / 1000
424
+ ]
425
  # create pie chart
426
+ labels = ['Total Fat', 'Saturated Fat', 'Cholesterol', 'Sodium', 'Total Carbohydrate', 'Dietary Fiber', 'Total Sugars', 'Protein', 'Vitamin C', 'Calcium', 'Iron', 'Potassium']
427
  fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
428
+ st.markdown("### Macronutrients Pie Chart ;) (In Grams)")
429
  st.plotly_chart(fig)
430
+ st.write("**Tags:** ", random_recipe['Tags'])
431
+ st.write("**Recipe URL:** ", random_recipe['Recipe URLs'])
432
  st.markdown("### JSON:")
433
  st.write(response_json)
434