amoldwalunj commited on
Commit
08eb2b9
·
1 Parent(s): 869c052

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import json
4
+ import numpy as np
5
+ #from fuzzywuzzy import fuzz
6
+
7
+ import pinecone
8
+ from sentence_transformers import SentenceTransformer
9
+
10
+ pinecone.init(api_key='f5112f8c-f27d-4af1-b427-0c0953c113b5', environment='asia-southeast1-gcp')
11
+
12
+ #model = SentenceTransformer('all-mpnet-base-v2',device='cpu')
13
+
14
+ loaded_model = SentenceTransformer(r"finetiuned_model")
15
+
16
+ def process_string(s):
17
+ return s.lower().replace('&', 'and')
18
+
19
+
20
+
21
+ index = pinecone.Index('ingradientsearch')
22
+
23
+
24
+ # Create a Streamlit app
25
+ def main():
26
+ st.set_page_config(page_title="Ingradients Matching App", page_icon=":smiley:", layout="wide")
27
+ st.title("Ingradients name matching App :smiley:")
28
+
29
+
30
+ st.header("Matches using embeddings (semantic search)")
31
+ st.write("Enter a ingradient name:")
32
+ st.write("e.g. Chicken")
33
+ input_string = st.text_input("")
34
+
35
+ input_string = process_string(input_string)
36
+
37
+ if st.button("Enter"):
38
+ st.write("Top 5 matches using semantic search:")
39
+
40
+ xq = 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, Group, score)),
52
+ columns =['Ingredient','score' ])
53
+
54
+ st.dataframe(final_result)
55
+
56
+ if __name__ == "__main__":
57
+ main()