File size: 2,313 Bytes
2e5ef0b
1920313
2e5ef0b
 
 
 
 
1920313
2e5ef0b
 
1920313
 
2e5ef0b
1920313
2e5ef0b
1920313
2e5ef0b
1920313
2e5ef0b
1920313
2e5ef0b
 
 
 
 
 
1920313
 
2e5ef0b
1920313
2e5ef0b
 
 
 
 
 
 
 
1920313
2e5ef0b
1920313
 
 
2e5ef0b
 
 
1920313
2e5ef0b
1920313
2e5ef0b
 
1920313
 
 
2e5ef0b
 
 
 
1920313
2e5ef0b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

# app.py
import gradio as gr
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download

MODEL_REPO = "DetectiveShadow/Grade_predictor"  # where assignment_predictor.pkl lives

def load_model():
    pipe = joblib.load(hf_hub_download(MODEL_REPO, "assignment_predictor.pkl"))
    return pipe

PIPE = load_model()

SUBJECTS = ["Math","Science","English","History","Tech","Drama","Elective"]
DIFFICULTY = ["Regular","Honors","AP"]
ASSIGN_TYPES = ["Assignment","Test","Project"]

def predict(attendance, hours, grade_level, subject, difficulty, assignment_type, confidence):
    row = pd.DataFrame([{
        "attendance": float(attendance),
        "hours_studied": int(hours),
        "grade_level": int(grade_level),
        "subject": subject,
        "course_difficulty": difficulty,
        "assignment_type": assignment_type,
        "confidence_before_assessment": int(confidence),
    }])
    score = float(PIPE.predict(row)[0])

    def to_letter(x):
        if x >= 90: return "A"
        if x >= 80: return "B"
        if x >= 70: return "C"
        if x >= 60: return "D"
        return "F"

    return {"Predicted Assignment Score": round(score, 1), "Letter": to_letter(score)}

with gr.Blocks(title="Assignment Score Predictor") as demo:
    gr.Markdown("# 📝 Assignment Score Predictor")
    gr.Markdown("Predict a single assignment score using your study & course details (no uploads).")

    with gr.Row():
        attendance = gr.Slider(0.5, 1.0, value=0.95, step=0.01, label="Attendance (0–1)")
        hours      = gr.Slider(0, 30, value=8, step=1, label="Hours studied")
    with gr.Row():
        grade_lvl  = gr.Slider(5, 12, value=11, step=1, label="Grade level")
        subject    = gr.Dropdown(SUBJECTS, value="Math", label="Subject", allow_custom_value=True)
    with gr.Row():
        difficulty = gr.Dropdown(DIFFICULTY, value="Regular", label="Course difficulty")
        a_type     = gr.Dropdown(ASSIGN_TYPES, value="Assignment", label="Assignment type")
    confidence = gr.Slider(0, 10, value=6, step=1, label="Confidence before assessment")

    go = gr.Button("Predict")
    out = gr.JSON(label="Prediction")

    go.click(predict, [attendance, hours, grade_lvl, subject, difficulty, a_type, confidence], out)

if __name__ == "__main__":
    demo.launch()