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