darshan8950's picture
Update main.py
468bd7c
from flask import Flask, request, jsonify
import json
app = Flask(__name__)
with open('data.json', 'r') as file:
data = json.load(file)
def recommend_courses(degree, stream, semester):
for deg in data['degrees']:
if deg['name'] == degree:
for strm in deg['streams']:
if strm['name'] == stream:
for sem in strm['semesters']:
if sem['semester_number'] == semester:
return sem['courses']
@app.route('/')
def home():
return jsonify({"message": "Welcome to the Recommendation API!"})
@app.route('/recommend', methods=['POST'])
def recommendation():
content = request.json
user_degree = content.get('degree')
user_stream = content.get('stream')
user_semester = content.get('semester')
if user_degree and user_stream and user_semester:
recommended_courses = recommend_courses(user_degree, user_stream, user_semester)
return jsonify({"Recommended Courses": recommended_courses})
else:
return jsonify({"error": "Invalid input"}), 400
if __name__ == '__main__':
app.run(debug=True)