predictor_app / app.py
Bisher2134's picture
Update app.py
39d90cc verified
Raw History Blame Contribute Delete
1.51 kB
!pip install pandas
!pip install sklearn
import gradio as gr # πŸ”Œ Build user interface
from sklearn.linear_model import LogisticRegression # 🎯 Simple ML classifier
import pandas as pd # πŸ“Š Data loading and prep
# Load and prepare data
Data = pd.read_csv('student_exam.csv') # Load dataset πŸ“„
# Features and target
features = ['studytime', 'failures', 'G1', 'G2']
target = 'G3'
# Convert G3 to binary pass/fail
Data[target] = Data[target].apply(lambda x: 1 if x >= 10 else 0)
X = Data[features]
y = Data[target]
# Train model
model = LogisticRegression(random_state=42)
model.fit(X, y)
# Prediction function
def predict_grade(study_time, failures, g1, g2):
input_data = pd.DataFrame([[study_time, failures, g1, g2]], columns=features)
prediction = model.predict(input_data)[0]
return "Pass βœ…" if prediction == 1 else "Fail ❌"
# Gradio interface
demo = gr.Interface(
fn=predict_grade, # Prediction function
inputs=[
gr.Number(label="Study Time (1-4)"), # ⏳ How much time student spends studying
gr.Number(label="Failures (0-4)"), # πŸ“‰ Number of past course failures
gr.Number(label="G1 Grade (0-20)"), # πŸ“ First period grade
gr.Number(label="G2 Grade (0-20)"), # πŸ“ Second period grade
],
outputs=gr.Text(label="Prediction: Pass or Fail"),
title="Student Exam Success Predictor", # πŸŽ“ App Title
description="Enter the student's data to predict if they will pass or fail the final exam."
)
demo.launch()