init
Browse files
app.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import time
|
4 |
+
|
5 |
+
import tensorflow as tf
|
6 |
+
from utils import load_prepare_image, model_pred, fetch_recipe
|
7 |
+
|
8 |
+
import sys
|
9 |
+
sys.path.insert(1, 'Api Data')
|
10 |
+
from RecipeData import fetchRecipeData
|
11 |
+
|
12 |
+
IMG_SIZE = (224, 224)
|
13 |
+
model_V1 = 'models/Seefood_model_v1.tflite'
|
14 |
+
model_V2 = 'models/Seefood_model_V2.tflite'
|
15 |
+
|
16 |
+
@st.cache()
|
17 |
+
def model_prediction(model, img_file, rescale):
|
18 |
+
img = load_prepare_image(img_file, IMG_SIZE, rescale=rescale)
|
19 |
+
prediction = model_pred(model, img)
|
20 |
+
sorceCode, recipe_data = fetchRecipeData(prediction)
|
21 |
+
return prediction, sorceCode, recipe_data
|
22 |
+
|
23 |
+
|
24 |
+
def main():
|
25 |
+
st.set_page_config(
|
26 |
+
page_title="SeeFood",
|
27 |
+
page_icon="🍔",
|
28 |
+
layout="wide",
|
29 |
+
initial_sidebar_state="expanded"
|
30 |
+
)
|
31 |
+
|
32 |
+
st.title('SeeFood🍔')
|
33 |
+
st.write('Upload a food image and get the recipe for that food and other details of that food')
|
34 |
+
|
35 |
+
col1, col2 = st.columns(2)
|
36 |
+
|
37 |
+
with col1:
|
38 |
+
# image uploading button
|
39 |
+
uploaded_file = st.file_uploader("Choose a file")
|
40 |
+
selected_model = st.selectbox('Select Model',('model 1', 'model 2'), index=1)
|
41 |
+
if uploaded_file is not None:
|
42 |
+
uploaded_img = uploaded_file.read()
|
43 |
+
|
44 |
+
col2.image(uploaded_file, width=500)
|
45 |
+
|
46 |
+
# butoon to make predictions
|
47 |
+
predict = st.button('Get Recipe!')
|
48 |
+
|
49 |
+
if predict:
|
50 |
+
if uploaded_file is not None:
|
51 |
+
with st.spinner('Please Wait 👩🍳'):
|
52 |
+
|
53 |
+
# setting model and rescalling
|
54 |
+
if selected_model == 'model 2':
|
55 |
+
pred_model = model_V2
|
56 |
+
pred_rescale = True
|
57 |
+
else:
|
58 |
+
pred_model = model_V1
|
59 |
+
pred_rescale = False
|
60 |
+
|
61 |
+
# makeing prediction and fetching food recipe form api
|
62 |
+
food, source_code, recipe_data = model_prediction(pred_model, uploaded_img, pred_rescale)
|
63 |
+
|
64 |
+
# asssigning caleoric breakdown data
|
65 |
+
percent_Protein = recipe_data['percentProtein']
|
66 |
+
percent_fat = recipe_data['percentFat']
|
67 |
+
percent_carbs = recipe_data['percentCarbs']
|
68 |
+
|
69 |
+
# food name message
|
70 |
+
col1.success(f"It's an {food}")
|
71 |
+
|
72 |
+
if source_code == 200:
|
73 |
+
# desplay food recipe
|
74 |
+
st.header(recipe_data['title']+" Recipe")
|
75 |
+
|
76 |
+
col3, col4 = st.columns(2)
|
77 |
+
|
78 |
+
with col3:
|
79 |
+
# Ingridents of recipie
|
80 |
+
st.subheader('Ingredients')
|
81 |
+
# st.info(recipe_data['ingridents'])
|
82 |
+
for i in recipe_data['ingridents']:
|
83 |
+
st.info(f"{i}")
|
84 |
+
# Inctuction for recipe
|
85 |
+
with col4:
|
86 |
+
st.subheader('Instructions')
|
87 |
+
st.info(recipe_data['instructions'])
|
88 |
+
# st.subheader('Caloric Breakdown')
|
89 |
+
'''
|
90 |
+
## Caloric Breakdown
|
91 |
+
'''
|
92 |
+
st.success(f'''
|
93 |
+
* Protien: {percent_Protein}%
|
94 |
+
* Fat: {percent_fat}%
|
95 |
+
* Carbohydrates: {percent_carbs}%
|
96 |
+
''')
|
97 |
+
|
98 |
+
|
99 |
+
else:
|
100 |
+
st.error('Something went wrong please try again :(')
|
101 |
+
|
102 |
+
|
103 |
+
else:
|
104 |
+
st.warning('Please Upload Image')
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
+
if __name__=='__main__':
|
110 |
+
main()
|