rushankg commited on
Commit
d562319
·
0 Parent(s):

Duplicate from rushankg/test-streamlit

Browse files
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.streamlit/config.toml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ [theme] # You have to add this line
2
+
3
+ primaryColor = '#FFFFFF' # Palo Alto Green
4
+
5
+ backgroundColor = '#820000' # Cardinal Red
6
+
7
+ secondaryBackgroundColor = '#820000' # Cardinal Red
8
+
9
+ textColor = '#FFFFFF' # White
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Test Streamlit
3
+ emoji: 🦀
4
+ colorFrom: green
5
+ colorTo: red
6
+ sdk: streamlit
7
+ sdk_version: 1.25.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: cc-by-2.0
11
+ duplicated_from: rushankg/test-streamlit
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import pandas as pd
4
+ import torch
5
+ import numpy as np
6
+
7
+ cosine_scores = pickle.load(open('cosine_scores.pkl','rb'))
8
+ coursedf = pd.read_pickle('course_df.pkl') # course_df uses titles to generate course recommendations
9
+ course_df_new = pd.read_pickle('course_df_new.pkl') #course_df_new makes recommendations using the entire description
10
+
11
+ course_title_list = [i + ": " + j for i, j in zip(coursedf['ref'].to_list(), coursedf['title'].to_list())]
12
+
13
+ def get_random_course():
14
+ row=coursedf.sample(1)
15
+ return row['ref'], row['title']
16
+
17
+ def recommend(index):
18
+ pairs = {}
19
+
20
+ for i in range(len(coursedf)):
21
+ pairs[coursedf.iloc[i,1]]=cosine_scores[index][i]
22
+
23
+ sorttemp = sorted(pairs.items(), key=lambda x:x[1], reverse=True)
24
+ sorted_final = dict(sorttemp[1:31])
25
+
26
+ return list(sorted_final.keys())
27
+
28
+ st.set_page_config(page_title='DiscoverCourses', page_icon=':bird:')
29
+ st.header('DiscoverCourses')
30
+ st.write('')
31
+
32
+ selected_course = st.selectbox('Pick a course from the dropdown:',course_title_list)
33
+
34
+ container = st.container()
35
+ maincol1, maincol2 = container.columns(2)
36
+ st.write('')
37
+
38
+ if maincol1.button('Recommend by title',use_container_width=True):
39
+ output=recommend(np.where((coursedf['ref']+": "+coursedf['title']) == selected_course)[0][0])
40
+ for result in output:
41
+ index=np.where(coursedf['title'] == result)[0][0]
42
+ course_id=coursedf.iloc[index,0]
43
+ st.subheader(course_id+": "+result)
44
+ with st.expander("See description"):
45
+ st.write(course_df_new.iloc[index,3]) #Using the new coursedf because it has proper descriptions for each course
46
+ link = "[ExploreCourses](https://explorecourses.stanford.edu/search?q="+course_id+"+"+result.replace(" ","+")+")"
47
+ st.markdown(link, unsafe_allow_html=True)
48
+ link = "[Carta](https://carta-beta.stanford.edu/results/"+course_id+")"
49
+ st.markdown(link, unsafe_allow_html=True)
50
+ st.divider()
51
+
52
+ if maincol2.button('Recommend by description',use_container_width=True):
53
+ index_new=np.where((coursedf['ref']+": "+coursedf['title']) == selected_course)[0][0]
54
+ rec_list=course_df_new.iloc[index_new,2]
55
+ for result in rec_list:
56
+ index=np.where(coursedf['title'] == result)[0][0]
57
+ course_id=coursedf.iloc[index,0]
58
+ st.subheader(course_id+": "+result)
59
+ with st.expander("See description"):
60
+ st.write(course_df_new.iloc[index,3]) #Using the new coursedf because it has proper descriptions for each course
61
+ link = "[ExploreCourses](https://explorecourses.stanford.edu/search?q="+course_id+"+"+result.replace(" ","+")+")"
62
+ st.markdown(link, unsafe_allow_html=True)
63
+ link = "[Carta](https://carta-beta.stanford.edu/results/"+course_id+")"
64
+ st.markdown(link, unsafe_allow_html=True)
65
+ st.divider()
66
+
67
+ st.write('© 2023 Rushank Goyal. All rights reserved. Source for the all-MiniLM-L6-v2 model: Wang, Wenhui, et al. "MiniLM: Deep Self-Attention Distillation for Task-Agnostic Compression of Pre-Trained Transformers." arXiv, 25 Feb. 2020, doi:10.48550/arXiv.2002.10957.')
cosine_scores.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f49c97656d3c2df641600b5560c9c6059dbb388c528b35a5d1d2822df4736d28
3
+ size 258438192
course_df.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a547aaaf1a76a586376e442fa355afc0a3d86ad44b32b3f85e0b4b37d7e1104a
3
+ size 4718547
course_df_new.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:062806ae754b8486468869c17e44d2fcb375cb79a8673e8c48656425997f1f74
3
+ size 7016497
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Pillow
2
+ pandas
3
+ numpy
4
+ streamlit
5
+ scikit-learn==1.0.2
6
+ torch