Spaces:
Runtime error
Runtime error
cache_resource using streamlit
Browse files
app.py
CHANGED
@@ -4,39 +4,41 @@ import pandas
|
|
4 |
from sentence_transformers import SentenceTransformer, util
|
5 |
import torch
|
6 |
|
7 |
-
# from sentence_transformers import SentenceTransformer, util
|
8 |
-
|
9 |
-
|
10 |
st.title('Arxiv Paper Recommendation')
|
11 |
paper_you_like = st.text_input(
|
12 |
"Enter the title of any paper you like 👇",
|
13 |
-
placeholder =
|
14 |
)
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
sentences = pickle.load(f)
|
20 |
|
21 |
-
with open('embeddings.pkl', 'rb') as f:
|
22 |
-
embeddings = pickle.load(f)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
|
27 |
-
# Calculating the similarity between titles
|
28 |
-
cosine_scores = util.cos_sim(embeddings, model.encode(paper_you_like))
|
29 |
|
30 |
-
|
|
|
|
|
|
|
31 |
|
|
|
32 |
|
|
|
|
|
33 |
top_similar_papers = torch.topk(cosine_scores,dim=0, k=5,sorted=True)
|
34 |
# top_similar_papers
|
35 |
|
36 |
-
# s = ''
|
37 |
-
|
38 |
for i in top_similar_papers.indices:
|
39 |
-
|
40 |
-
st.write(sentences[i.item()])
|
41 |
-
# st.text(s)
|
42 |
-
|
|
|
4 |
from sentence_transformers import SentenceTransformer, util
|
5 |
import torch
|
6 |
|
|
|
|
|
|
|
7 |
st.title('Arxiv Paper Recommendation')
|
8 |
paper_you_like = st.text_input(
|
9 |
"Enter the title of any paper you like 👇",
|
10 |
+
placeholder = None
|
11 |
)
|
12 |
|
13 |
+
@st.cache_resource
|
14 |
+
def get_sentences_data():
|
15 |
+
with open('sentences.pkl', 'rb') as f:
|
16 |
+
sentences = pickle.load(f)
|
17 |
+
return sentences
|
18 |
|
19 |
+
sentences = get_sentences_data()
|
|
|
20 |
|
|
|
|
|
21 |
|
22 |
+
@st.cache_resource
|
23 |
+
def get_embeddings_data():
|
24 |
+
with open('embeddings.pkl', 'rb') as f:
|
25 |
+
embeddings = pickle.load(f)
|
26 |
+
return embeddings
|
27 |
|
28 |
+
embeddings = get_embeddings_data()
|
29 |
|
|
|
|
|
30 |
|
31 |
+
@st.cache_resource
|
32 |
+
def get_model():
|
33 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
34 |
+
return model
|
35 |
|
36 |
+
model = get_model()
|
37 |
|
38 |
+
# Calculating the similarity between titles
|
39 |
+
cosine_scores = util.cos_sim(embeddings, model.encode(paper_you_like))
|
40 |
top_similar_papers = torch.topk(cosine_scores,dim=0, k=5,sorted=True)
|
41 |
# top_similar_papers
|
42 |
|
|
|
|
|
43 |
for i in top_similar_papers.indices:
|
44 |
+
st.write(sentences[i.item()])
|
|
|
|
|
|