ntam0001 commited on
Commit
925e18d
Β·
verified Β·
1 Parent(s): ad846d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -3,15 +3,13 @@ import pandas as pd
3
  import numpy as np
4
  import tensorflow as tf
5
  from tensorflow import keras
6
- from sklearn.preprocessing import StandardScaler, LabelEncoder
7
- import pickle # Missing import
8
 
9
- # Load model and preprocessing objects (replace paths if needed)
10
- model = keras.models.load_model('model.h5')
11
  with open('scaler.pkl', 'rb') as f:
12
  scaler = pickle.load(f)
13
- with open('label_encoder.pkl', 'rb') as f:
14
- label_encoder = pickle.load(f)
15
 
16
  def predict_eligibility(theory_score, practice_score):
17
  """Predicts eligibility given theory and practice scores."""
@@ -26,7 +24,7 @@ def predict_eligibility(theory_score, practice_score):
26
  # Predict
27
  proba = model.predict(scaled_input, verbose=0)[0][0]
28
  prediction = int(proba > 0.5)
29
- class_name = label_encoder.inverse_transform([prediction])[0]
30
 
31
  # Confidence score
32
  confidence = proba if prediction else (1 - proba)
@@ -35,7 +33,7 @@ def predict_eligibility(theory_score, practice_score):
35
  return (
36
  class_name, # First output: Prediction label
37
  f"{confidence * 100:.2f}%", # Second output: Confidence
38
- "❌ No" if prediction else "βœ… Yes" # Third output: Eligibility status
39
  )
40
 
41
  except Exception as e:
@@ -51,7 +49,7 @@ demo = gr.Interface(
51
  gr.Slider(0, 30, value=0, step=1, label="Practice Score")
52
  ],
53
  outputs=[
54
- gr.Textbox(label="Prediction"), # Changed from gr.Label to gr.Textbox
55
  gr.Textbox(label="Confidence"),
56
  gr.Textbox(label="Eligibility Status")
57
  ],
 
3
  import numpy as np
4
  import tensorflow as tf
5
  from tensorflow import keras
6
+ from sklearn.preprocessing import StandardScaler
7
+ import pickle
8
 
9
+ # Load model and scaler (replace paths if needed)
10
+ model = keras.models.load_model('eligibility_predictor.h5') # Changed to match your saved model name
11
  with open('scaler.pkl', 'rb') as f:
12
  scaler = pickle.load(f)
 
 
13
 
14
  def predict_eligibility(theory_score, practice_score):
15
  """Predicts eligibility given theory and practice scores."""
 
24
  # Predict
25
  proba = model.predict(scaled_input, verbose=0)[0][0]
26
  prediction = int(proba > 0.5)
27
+ class_name = "Eligible" if prediction else "Not eligible"
28
 
29
  # Confidence score
30
  confidence = proba if prediction else (1 - proba)
 
33
  return (
34
  class_name, # First output: Prediction label
35
  f"{confidence * 100:.2f}%", # Second output: Confidence
36
+ "βœ… Yes" if prediction else "❌ No" # Third output: Eligibility status
37
  )
38
 
39
  except Exception as e:
 
49
  gr.Slider(0, 30, value=0, step=1, label="Practice Score")
50
  ],
51
  outputs=[
52
+ gr.Textbox(label="Prediction"),
53
  gr.Textbox(label="Confidence"),
54
  gr.Textbox(label="Eligibility Status")
55
  ],