Spaces:
Runtime error
Runtime error
Download app.py from Bisher2134/predictor_app: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/Bisher2134/predictor_app/resolve/main/app.py
- Command line
-
hf download hf://spaces/Bisher2134/predictor_app/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Bisher2134/predictor_app/resolve/main/app.py
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() |