Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,10 +3,10 @@ import pickle
|
|
| 3 |
import pandas as pd
|
| 4 |
import torch
|
| 5 |
import numpy as np
|
| 6 |
-
from streamlit_card import card
|
| 7 |
|
| 8 |
cosine_scores = pickle.load(open('cosine_scores.pkl','rb'))
|
| 9 |
-
coursedf = pd.read_pickle('course_df.pkl')
|
|
|
|
| 10 |
|
| 11 |
course_title_list = [i + ": " + j for i, j in zip(coursedf['ref'].to_list(), coursedf['title'].to_list())]
|
| 12 |
|
|
@@ -29,19 +29,26 @@ def recommend(index):
|
|
| 29 |
st.set_page_config(page_title='DiscoverCourses', page_icon=':book:')
|
| 30 |
st.title('DiscoverCourses')
|
| 31 |
|
| 32 |
-
selected_course = st.selectbox('
|
| 33 |
|
| 34 |
-
if st.button('
|
| 35 |
output=recommend(np.where((coursedf['ref']+": "+coursedf['title']) == selected_course)[0][0])
|
| 36 |
for result in output:
|
| 37 |
index=np.where(coursedf['title'] == result)[0][0]
|
| 38 |
course_id=coursedf.iloc[index,0]
|
| 39 |
st.subheader(course_id+": "+result)
|
| 40 |
-
|
|
|
|
| 41 |
st.markdown(link, unsafe_allow_html=True)
|
| 42 |
st.divider()
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
|
|
| 29 |
st.set_page_config(page_title='DiscoverCourses', page_icon=':book:')
|
| 30 |
st.title('DiscoverCourses')
|
| 31 |
|
| 32 |
+
selected_course = st.selectbox('Pick a course',course_title_list)
|
| 33 |
|
| 34 |
+
if st.button('Recommend by title'):
|
| 35 |
output=recommend(np.where((coursedf['ref']+": "+coursedf['title']) == selected_course)[0][0])
|
| 36 |
for result in output:
|
| 37 |
index=np.where(coursedf['title'] == result)[0][0]
|
| 38 |
course_id=coursedf.iloc[index,0]
|
| 39 |
st.subheader(course_id+": "+result)
|
| 40 |
+
st.text(course_df_new.iloc[index,3]) #Using the new coursedf because it has proper descriptions for each course
|
| 41 |
+
link = "[ExploreCourses](https://explorecourses.stanford.edu/search?q="+course_id+" "+result+")"
|
| 42 |
st.markdown(link, unsafe_allow_html=True)
|
| 43 |
st.divider()
|
| 44 |
+
|
| 45 |
+
if st.button('Recommend by description'):
|
| 46 |
+
index_new=np.where((coursedf['ref']+": "+coursedf['title']) == selected_course)[0][0]
|
| 47 |
+
rec_list=course_df_new.iloc[index_new,2]
|
| 48 |
+
for result in rec_list:
|
| 49 |
+
course_id=coursedf.iloc[index,0]
|
| 50 |
+
st.subheader(course_id+": "+result)
|
| 51 |
+
st.text(course_df_new.iloc[index,3]) #Using the new coursedf because it has proper descriptions for each course
|
| 52 |
+
link = "[ExploreCourses](https://explorecourses.stanford.edu/search?q="+course_id+" "+result+")"
|
| 53 |
+
st.markdown(link, unsafe_allow_html=True)
|
| 54 |
+
st.divider()
|