Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,9 @@ from transformers import pipeline
|
|
7 |
import numpy as np
|
8 |
from transformers import AutoFeatureExtractor
|
9 |
from transformers import AutoModelForImageClassification
|
|
|
|
|
|
|
10 |
|
11 |
st.set_page_config(layout='wide',
|
12 |
page_title='Food Category Classification & Recipes'
|
@@ -192,9 +195,23 @@ def main():
|
|
192 |
st.write("**Iron:** ", random_recipe['Iron'])
|
193 |
st.write("**Potassium:** ", random_recipe['Potassium'])
|
194 |
st.write("**Tags:** ", random_recipe['Tags'])
|
195 |
-
st.write("**Recipe URL:** ", random_recipe['Recipe URLs'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
st.markdown("### JSON:")
|
197 |
-
st.write(response_json)
|
198 |
else:
|
199 |
st.markdown("### Recommended Recipe:")
|
200 |
st.write("**Title:** ", response_json[0]['Title'])
|
@@ -225,8 +242,22 @@ def main():
|
|
225 |
st.write("**Potassium:** ", response_json[0]['Potassium'])
|
226 |
st.write("**Tags:** ", response_json[0]['Tags'])
|
227 |
st.write("**Recipe URL:** ", response_json[0]['Recipe URLs'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
st.markdown("### JSON:")
|
229 |
-
st.write(response_json)
|
230 |
|
231 |
st.markdown("<hr style='text-align: center;'>", unsafe_allow_html=True)
|
232 |
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)
|
|
|
7 |
import numpy as np
|
8 |
from transformers import AutoFeatureExtractor
|
9 |
from transformers import AutoModelForImageClassification
|
10 |
+
import plotly.graph_objects as go
|
11 |
+
import plotly
|
12 |
+
import re
|
13 |
|
14 |
st.set_page_config(layout='wide',
|
15 |
page_title='Food Category Classification & Recipes'
|
|
|
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:
|
216 |
st.markdown("### Recommended Recipe:")
|
217 |
st.write("**Title:** ", response_json[0]['Title'])
|
|
|
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 |
|
262 |
st.markdown("<hr style='text-align: center;'>", unsafe_allow_html=True)
|
263 |
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)
|