Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions api_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async def health_check():
raise HTTPException(status_code=500, detail="Service unhealthy")


@app.get("/api/v1/predict")
@app.post("/api/v1/predict")
async def predict_exam_score(data: StudentProfile):
"""Predict a student's exam score from their profile."""
if not MODEL_READY:
Expand Down Expand Up @@ -221,8 +221,8 @@ async def predict_exam_score(data: StudentProfile):
"INSERT INTO students (name, age, study_hours_per_day, predicted_score) VALUES (?,?,?,?)",
(data.name, data.age, data.studyHours, score),
)
conn.close()
conn.commit()
conn.commit()
conn.close()
except Exception as e:
raise HTTPException(status_code=500, detail=f"DB write failed: {e}")

Expand Down Expand Up @@ -268,8 +268,10 @@ async def get_analytics():
scores = [r["predicted_score"] for r in rows if r["predicted_score"] is not None]
num_students = len(scores)
total_score = sum(scores)

avg_score = total_score / num_students
if num_students>0 :
avg_score = total_score / num_students
else :
avg_score = 0

distribution = {
"A (90-100)" : sum(1 for s in scores if s >= 90),
Expand Down