CoolFace
Apppublic

kmrmanish/LPI_Course_Recommendation_System

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
2likes
app.py74 linesDownload Raw Back to root
1import streamlit as st2import difflib3import pandas as pd4import numpy as np5import re6import nltk7from nltk.corpus import stopwords8from nltk.stem.porter import PorterStemmer9from sklearn.feature_extraction.text import TfidfVectorizer10from sklearn.metrics.pairwise import cosine_similarity11 12# Download NLTK stopwords if not already done13nltk.download('stopwords')14 15# Read the data16lpi_df = pd.read_csv('Learning Pathway Index.csv')17 18# Rename columns19lpi_df.rename(columns={20    "Course / Learning material": "Course_Learning_Material",21    "Course Level": "Course_Level",22    "Type (Free or Paid)": "Type",23    "Module / Sub-module \nDifficulty level": "Difficulty_Level",24    "Keywords / Tags / Skills / Interests / Categories": "Keywords"25}, inplace=True)26 27# Combine features28lpi_df['combined_features'] = lpi_df['Course_Learning_Material'] + ' ' + lpi_df['Source'] + ' ' + lpi_df['Course_Level'] + ' ' + lpi_df['Type'] + ' ' + lpi_df['Module'] + ' ' + lpi_df['Difficulty_Level'] + ' ' + lpi_df['Keywords']29 30# Text preprocessing31combined_features = lpi_df['combined_features']32porter_stemmer = PorterStemmer()33 34def stemming(content):35    stemmed_content = re.sub('[^a-zA-Z]', ' ', content)36    stemmed_content = stemmed_content.lower()37    stemmed_content = stemmed_content.split()38    stemmed_content = [porter_stemmer.stem(word) for word in stemmed_content if not word in stopwords.words('english')]39    stemmed_content = ' '.join(stemmed_content)40    return stemmed_content41 42combined_features = combined_features.apply(stemming)43 44# TF-IDF and similarity45vectorizer = TfidfVectorizer()46vectorizer.fit(combined_features)47combined_features = vectorizer.transform(combined_features)48similarity = cosine_similarity(combined_features)49 50# Streamlit app51st.title('Learning Pathway Index Course Recommendation')52user_input = st.text_input('Enter What You Want to Learn : ')53 54if user_input:55    list_of_all_titles = lpi_df['Module'].tolist()56    find_close_match = difflib.get_close_matches(user_input, list_of_all_titles)57 58    if find_close_match:59        close_match = find_close_match[0]60        index_of_the_course = lpi_df[lpi_df.Module == close_match].index.values[0]61        similarity_score = list(enumerate(similarity[index_of_the_course]))62        sorted_similar_course = sorted(similarity_score, key=lambda x: x[1], reverse=True)63 64        st.subheader('Courses suggested for you:')65        for i, course in enumerate(sorted_similar_course[:30], start=1):66            index = course[0]67            title_from_index = lpi_df.loc[index, 'Module']68            st.write(f"{i}. {title_from_index}")69 70        if len(sorted_similar_course) == 0:71            st.write('No close matches found.')72    else:73        st.write('No close matches found.')74