Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import torch
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from sentence_transformers import SentenceTransformer, util
|
| 5 |
+
import pickle
|
| 6 |
+
|
| 7 |
+
# Load data
|
| 8 |
+
data = pd.read_csv("/content/arxiv_data.csv")
|
| 9 |
+
titles = data["titles"]
|
| 10 |
+
|
| 11 |
+
# Load pre-trained SentenceTransformer model
|
| 12 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 13 |
+
|
| 14 |
+
# Load saved embeddings
|
| 15 |
+
with open("/content/embedding.pkl", "rb") as f:
|
| 16 |
+
Lencode = pickle.load(f)
|
| 17 |
+
|
| 18 |
+
# Load saved model
|
| 19 |
+
with open("/content/ModelRec.pkl", "rb") as f:
|
| 20 |
+
lModelRec = pickle.load(f)
|
| 21 |
+
|
| 22 |
+
def recomm(inputPaper):
|
| 23 |
+
encodePaper = lModelRec.encode(inputPaper)
|
| 24 |
+
cosine_score = util.cos_sim(Lencode, encodePaper)
|
| 25 |
+
top_scores = torch.topk(cosine_score, dim=0, k=4)
|
| 26 |
+
paperList = []
|
| 27 |
+
for i in top_scores.indices:
|
| 28 |
+
paperList.append(titles[i.item()])
|
| 29 |
+
return paperList
|
| 30 |
+
|
| 31 |
+
# Streamlit UI
|
| 32 |
+
st.title("Paper Recommendation System")
|
| 33 |
+
|
| 34 |
+
input_paper = st.text_input("Enter the name of the paper")
|
| 35 |
+
|
| 36 |
+
if st.button("Recommend"):
|
| 37 |
+
recommended_papers = recomm(input_paper)
|
| 38 |
+
st.write("Recommended Papers:")
|
| 39 |
+
for paper in recommended_papers:
|
| 40 |
+
st.write(paper)
|