test-streamlit / app.py
rushankg's picture
Update app.py
bd80b62
raw
history blame
893 Bytes
import streamlit as st
import pickle
import pandas as pd
import torch
cosine_scores = pickle.load(open('cosine_scores.pkl','rb'))
coursedf = pd.read_pickle('course_df.pkl')
course_title_list = coursedf['title'].to_list()
def get_random_course():
row=coursedf.sample(1)
return row['ref'], row['title']
def recommend(coursename):
pairs = {}
for i in range(len(coursedf)):
pairs[coursedf.iloc[i,1]]=cosine_scores[index][i]
sorttemp = sorted(pairs.items(), key=lambda x:x[1], reverse=True)
sorted_final = dict(sorttemp[1:31])
return list(sorted_final.keys())
st.set_page_config(page_title='DiscoverCourses', page_icon=':book:')
st.title('DiscoverCourses')
selected_course = st.selectbox('Please select a course',course_title_list)
if st.button('I want more like this!'):
st.write(recommend(np.where(coursedf['title'] == selected_course)[0][0]))