Spaces:
Runtime error
Runtime error
Commit
·
c9c1394
1
Parent(s):
4da94a0
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ pinecone.init(api_key='f5112f8c-f27d-4af1-b427-0c0953c113b5', environment='asia-
|
|
11 |
|
12 |
#model = SentenceTransformer('all-mpnet-base-v2',device='cpu')
|
13 |
|
14 |
-
|
15 |
|
16 |
def process_string(s):
|
17 |
return s.lower().replace('&', 'and')
|
@@ -21,14 +21,18 @@ def process_string(s):
|
|
21 |
index = pinecone.Index('ingradientsearch')
|
22 |
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
def main():
|
26 |
-
st.set_page_config(page_title="
|
27 |
-
st.title("
|
28 |
|
29 |
-
|
30 |
st.header("Matches using embeddings (semantic search)")
|
31 |
-
st.write("Enter
|
32 |
st.write("e.g. Chicken")
|
33 |
input_string = st.text_input("")
|
34 |
|
@@ -37,18 +41,18 @@ def main():
|
|
37 |
if st.button("Enter"):
|
38 |
st.write("Top 5 matches using semantic search:")
|
39 |
|
|
|
40 |
xq = loaded_model.encode([input_string]).tolist()
|
41 |
result = index.query(xq, top_k=5, includeMetadata=True)
|
42 |
|
43 |
Ingredient=[]
|
44 |
-
Group=[]
|
45 |
score=[]
|
46 |
for matches in result['matches']:
|
47 |
Ingredient.append(matches['metadata']['Ingredient'])
|
48 |
-
#Group.append(matches['metadata']['Group'])
|
49 |
score.append(matches['score'])
|
50 |
|
51 |
-
final_result= pd.DataFrame(list(zip(Ingredient,
|
52 |
columns =['Ingredient','score' ])
|
53 |
|
54 |
st.dataframe(final_result)
|
|
|
11 |
|
12 |
#model = SentenceTransformer('all-mpnet-base-v2',device='cpu')
|
13 |
|
14 |
+
#
|
15 |
|
16 |
def process_string(s):
|
17 |
return s.lower().replace('&', 'and')
|
|
|
21 |
index = pinecone.Index('ingradientsearch')
|
22 |
|
23 |
|
24 |
+
|
25 |
+
|
26 |
+
@st.cache(allow_output_mutation=True)
|
27 |
+
def load_model():
|
28 |
+
return SentenceTransformer(r"finetiuned_model")
|
29 |
+
|
30 |
def main():
|
31 |
+
st.set_page_config(page_title="Ingredients Matching App", page_icon=":smiley:", layout="wide")
|
32 |
+
st.title("Ingredients name matching App :smiley:")
|
33 |
|
|
|
34 |
st.header("Matches using embeddings (semantic search)")
|
35 |
+
st.write("Enter an ingredient name:")
|
36 |
st.write("e.g. Chicken")
|
37 |
input_string = st.text_input("")
|
38 |
|
|
|
41 |
if st.button("Enter"):
|
42 |
st.write("Top 5 matches using semantic search:")
|
43 |
|
44 |
+
loaded_model = load_model() # Load the model using the cached function
|
45 |
xq = loaded_model.encode([input_string]).tolist()
|
46 |
result = index.query(xq, top_k=5, includeMetadata=True)
|
47 |
|
48 |
Ingredient=[]
|
49 |
+
#Group=[]
|
50 |
score=[]
|
51 |
for matches in result['matches']:
|
52 |
Ingredient.append(matches['metadata']['Ingredient'])
|
|
|
53 |
score.append(matches['score'])
|
54 |
|
55 |
+
final_result= pd.DataFrame(list(zip(Ingredient, score)),
|
56 |
columns =['Ingredient','score' ])
|
57 |
|
58 |
st.dataframe(final_result)
|