Spaces:
Sleeping
Sleeping
Rename recommender.py to database_recommender.py
Browse files3 unmodified lines4567891011269 unmodified lines2812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273 unmodified linesfrom sklearn.preprocessing import LabelEncoder, StandardScalerimport joblibimport jsonimport osimport requestsclass CourseRecommender:def __init__(self):269 unmodified linesself.scaler = model_data['scaler']self.label_encoders = model_data['label_encoders']# ===== UI helper for Hugging Face integration =====def get_course_recommendations_ui(recommender: "CourseRecommender", stanine, gwa, strand, hobbies) -> str:if recommender is None:return "Sorry, the recommendation system is not available at the moment. Please try again later."try:try:stanine = int(stanine.strip()) if isinstance(stanine, str) else int(stanine)except (ValueError, TypeError, AttributeError):return "❌ Stanine score must be a valid number between 1 and 9"try:gwa = float(gwa.strip()) if isinstance(gwa, str) else float(gwa)except (ValueError, TypeError, AttributeError):return "❌ GWA must be a valid number between 75 and 100"if not (1 <= stanine <= 9):return "❌ Stanine score must be between 1 and 9"if not (75 <= gwa <= 100):return "❌ GWA must be between 75 and 100"if not strand:return "❌ Please select a strand"if not hobbies or not str(hobbies).strip():return "❌ Please enter your hobbies/interests"recommendations = recommender.recommend_courses(stanine=stanine,gwa=gwa,strand=strand,hobbies=str(hobbies))if not recommendations:return "No recommendations available at the moment."response = f"## 🎯 Course Recommendations for You\n\n"response += f"**Profile:** Stanine {stanine}, GWA {gwa}, {strand} Strand\n"response += f"**Interests:** {hobbies}\n\n"for i, rec in enumerate(recommendations, 1):response += f"### {i}. {rec['code']} - {rec['name']}\n"response += f"**Match Score:** {rec.get('rating', rec.get('probability', 0)):.1f}%\n\n"return responseexcept Exception as e:return f"❌ Error getting recommendations: {str(e)}"# Example usageif __name__ == "__main__":recommender = CourseRecommender()3 unmodified lines456789269 unmodified lines2792802812822832843 unmodified linesfrom sklearn.preprocessing import LabelEncoder, StandardScalerimport joblibimport jsonclass CourseRecommender:def __init__(self):269 unmodified linesself.scaler = model_data['scaler']self.label_encoders = model_data['label_encoders']# Example usageif __name__ == "__main__":recommender = CourseRecommender()
recommender.py → database_recommender.pyRenamed-43