Spaces:
Sleeping
Sleeping
Commit
Β·
9739f96
1
Parent(s):
8435df6
Optimised load take #3
Browse files
app.py
CHANGED
@@ -42,8 +42,8 @@ def detect_food(query, text_emb, labels, k=1):
|
|
42 |
|
43 |
def run_search(food_image, col2):
|
44 |
|
45 |
-
|
46 |
-
|
47 |
|
48 |
# emb_filename = './Pretrained/food_embeddings.pkl'
|
49 |
# text_emb = torch.load(emb_filename, map_location=torch.device('cpu'))
|
@@ -52,11 +52,12 @@ def run_search(food_image, col2):
|
|
52 |
food_recognised, score = results[0]
|
53 |
|
54 |
# del text_emb
|
55 |
-
|
56 |
|
57 |
import pysos
|
58 |
-
id2recipe = pysos.Dict("./Pretrained/id2recipe")
|
59 |
food2id = pysos.Dict("./Pretrained/food2id")
|
|
|
|
|
60 |
|
61 |
|
62 |
id = food2id[food_recognised]
|
@@ -73,7 +74,7 @@ def run_search(food_image, col2):
|
|
73 |
source= id2recipe[id]['recipesource']
|
74 |
|
75 |
|
76 |
-
del id2recipe
|
77 |
del food2id
|
78 |
|
79 |
st.markdown("<br/>", unsafe_allow_html=True)
|
@@ -125,7 +126,7 @@ if 'models_loaded' not in st.session_state:
|
|
125 |
st.title('WTF - What The Food π€¬')
|
126 |
st.subheader("Image to Recipe - 1.5M foods supported")
|
127 |
st.markdown("Built for fun with π by a quintessential foodie - Prithivi Da, The maker of [Gramformer](https://github.com/PrithivirajDamodaran/Gramformer), [Styleformer](https://github.com/PrithivirajDamodaran/Styleformer) and [Parrot paraphraser](https://github.com/PrithivirajDamodaran/Parrot_Paraphraser) | [@prithivida](https://twitter.com/prithivida) |[[GitHub]](https://github.com/PrithivirajDamodaran)", unsafe_allow_html=True)
|
128 |
-
st.markdown("""<i> (Read Me: The idea
|
129 |
|
130 |
|
131 |
def load_image(image_file):
|
@@ -133,7 +134,7 @@ def load_image(image_file):
|
|
133 |
return img
|
134 |
|
135 |
def load_models():
|
136 |
-
with st.spinner(text="Loading
|
137 |
os.system("python -m spacy download en_core_web_sm")
|
138 |
nlp = spacy.load('en_core_web_sm')
|
139 |
nlp.add_pipe('dbpedia_spotlight')
|
@@ -142,13 +143,11 @@ def load_models():
|
|
142 |
st.session_state['nlp'] = nlp
|
143 |
st.session_state['model'] = model
|
144 |
st.session_state['stop_words'] = stop_words
|
145 |
-
|
146 |
-
# food2id = pysos.Dict("./Pretrained/food2id")
|
147 |
-
#
|
148 |
-
#
|
149 |
-
|
150 |
-
labels = pickle.load(fIn)
|
151 |
-
st.session_state['labels'] = labels
|
152 |
emb_filename = './Pretrained/food_embeddings.pkl'
|
153 |
text_emb = torch.load(emb_filename, map_location=torch.device('cpu'))
|
154 |
st.session_state['text_emb'] = text_emb
|
@@ -166,10 +165,11 @@ image_file = st.file_uploader("", type=["jpg","jpeg"])
|
|
166 |
nlp = st.session_state['nlp']
|
167 |
model = st.session_state['model']
|
168 |
stop_words = st.session_state['stop_words']
|
169 |
-
|
170 |
-
# food2id = st.session_state['food2id']
|
171 |
-
labels = st.session_state['labels']
|
172 |
text_emb = st.session_state['text_emb']
|
|
|
|
|
|
|
173 |
|
174 |
col1, col2 = st.columns(2)
|
175 |
|
|
|
42 |
|
43 |
def run_search(food_image, col2):
|
44 |
|
45 |
+
with open("./Pretrained/labels.pkl", 'rb') as fIn:
|
46 |
+
labels = pickle.load(fIn)
|
47 |
|
48 |
# emb_filename = './Pretrained/food_embeddings.pkl'
|
49 |
# text_emb = torch.load(emb_filename, map_location=torch.device('cpu'))
|
|
|
52 |
food_recognised, score = results[0]
|
53 |
|
54 |
# del text_emb
|
55 |
+
del labels
|
56 |
|
57 |
import pysos
|
|
|
58 |
food2id = pysos.Dict("./Pretrained/food2id")
|
59 |
+
# id2recipe = pysos.Dict("./Pretrained/id2recipe")
|
60 |
+
|
61 |
|
62 |
|
63 |
id = food2id[food_recognised]
|
|
|
74 |
source= id2recipe[id]['recipesource']
|
75 |
|
76 |
|
77 |
+
# del id2recipe
|
78 |
del food2id
|
79 |
|
80 |
st.markdown("<br/>", unsafe_allow_html=True)
|
|
|
126 |
st.title('WTF - What The Food π€¬')
|
127 |
st.subheader("Image to Recipe - 1.5M foods supported")
|
128 |
st.markdown("Built for fun with π by a quintessential foodie - Prithivi Da, The maker of [Gramformer](https://github.com/PrithivirajDamodaran/Gramformer), [Styleformer](https://github.com/PrithivirajDamodaran/Styleformer) and [Parrot paraphraser](https://github.com/PrithivirajDamodaran/Parrot_Paraphraser) | [@prithivida](https://twitter.com/prithivida) |[[GitHub]](https://github.com/PrithivirajDamodaran)", unsafe_allow_html=True)
|
129 |
+
st.markdown("""<i> (Read Me: The idea: Food Image => Recipe. So it works on single foods and platters <p style='color:red; display:inline'> but May Not perform well on custom combinations or hyper-local foods.</p>) </i>""", unsafe_allow_html=True)
|
130 |
|
131 |
|
132 |
def load_image(image_file):
|
|
|
134 |
return img
|
135 |
|
136 |
def load_models():
|
137 |
+
with st.spinner(text="Loading models, please wait..."):
|
138 |
os.system("python -m spacy download en_core_web_sm")
|
139 |
nlp = spacy.load('en_core_web_sm')
|
140 |
nlp.add_pipe('dbpedia_spotlight')
|
|
|
143 |
st.session_state['nlp'] = nlp
|
144 |
st.session_state['model'] = model
|
145 |
st.session_state['stop_words'] = stop_words
|
146 |
+
st.session_state['id2recipe'] = pysos.Dict("./Pretrained/id2recipe")
|
147 |
+
# st.session_state['food2id'] = pysos.Dict("./Pretrained/food2id")
|
148 |
+
# with open("./Pretrained/labels.pkl", 'rb') as fIn:
|
149 |
+
# labels = pickle.load(fIn)
|
150 |
+
# st.session_state['labels'] = labels
|
|
|
|
|
151 |
emb_filename = './Pretrained/food_embeddings.pkl'
|
152 |
text_emb = torch.load(emb_filename, map_location=torch.device('cpu'))
|
153 |
st.session_state['text_emb'] = text_emb
|
|
|
165 |
nlp = st.session_state['nlp']
|
166 |
model = st.session_state['model']
|
167 |
stop_words = st.session_state['stop_words']
|
168 |
+
id2recipe = st.session_state['id2recipe']
|
|
|
|
|
169 |
text_emb = st.session_state['text_emb']
|
170 |
+
# food2id = st.session_state['food2id']
|
171 |
+
# labels = st.session_state['labels']
|
172 |
+
|
173 |
|
174 |
col1, col2 = st.columns(2)
|
175 |
|