shubham142000 commited on
Commit
2a5d1f7
·
verified ·
1 Parent(s): 5ee7d96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py CHANGED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from sklearn.feature_extraction.text import TfidfVectorizer
4
+ from sklearn.metrics.pairwise import cosine_similarity
5
+ from sklearn.neighbors import NearestNeighbors
6
+
7
+ # Function to recommend papers
8
+ def recommend_papers(positive_df, unlabelled_df, model="tfidf"):
9
+ if model == "tfidf":
10
+ # Use TF-IDF Vectorizer
11
+ vectorizer = TfidfVectorizer(stop_words='english')
12
+ positive_matrix = vectorizer.fit_transform(positive_df['abstract'])
13
+ unlabelled_matrix = vectorizer.transform(unlabelled_df['abstract'])
14
+ elif model == "nn":
15
+ # Use Nearest Neighbors
16
+ nn_model = NearestNeighbors(n_neighbors=5, algorithm='auto')
17
+ nn_model.fit(positive_df['abstract'])
18
+ distances, indices = nn_model.kneighbors(unlabelled_df['abstract'])
19
+ return indices
20
+
21
+ # Streamlit app
22
+ def main():
23
+ st.title("ArXiv Feed Recommendations")
24
+
25
+ # User input for model selection
26
+ model = st.selectbox("Select Model", ["TF-IDF", "Nearest Neighbors"])
27
+
28
+ # Upload CSV files
29
+ st.subheader("Upload Positive Labeled CSV")
30
+ positive_file = st.file_uploader("Upload CSV", type=['csv'])
31
+ st.subheader("Upload Unlabelled Data CSV")
32
+ unlabelled_file = st.file_uploader("Upload CSV", type=['csv'])
33
+
34
+ if positive_file is not None and unlabelled_file is not None:
35
+ # Read CSV files
36
+ positive_df = pd.read_csv(positive_file)
37
+ unlabelled_df = pd.read_csv(unlabelled_file)
38
+
39
+ # Show uploaded data
40
+ st.subheader("Positive Labeled Data")
41
+ st.write(positive_df)
42
+ st.subheader("Unlabelled Data")
43
+ st.write(unlabelled_df)
44
+
45
+ # Button to trigger recommendation
46
+ if st.button("Recommend"):
47
+ # Call recommend_papers function
48
+ recommended_indices = recommend_papers(positive_df, unlabelled_df, model.lower())
49
+ st.write(recommended_indices)
50
+
51
+ # Download CSV
52
+ st.markdown(get_csv_download_link(recommended_indices), unsafe_allow_html=True)
53
+
54
+ # Function to generate a download link for CSV
55
+ def get_csv_download_link(data):
56
+ csv = data.to_csv(index=False)
57
+ b64 = base64.b64encode(csv.encode()).decode()
58
+ href = f'<a href="data:file/csv;base64,{b64}" download="recommendations.csv">Download CSV</a>'
59
+ return href
60
+
61
+ if __name__ == "__main__":
62
+ main()