Update app.py
Browse files
app.py
CHANGED
|
@@ -4,17 +4,27 @@ 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 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def predict_eligibility(theory_score, practice_score):
|
| 15 |
"""Predicts eligibility given theory and practice scores."""
|
| 16 |
try:
|
| 17 |
-
# Preprocess input
|
| 18 |
input_df = pd.DataFrame({
|
| 19 |
'theory': [theory_score],
|
| 20 |
'practice': [practice_score]
|
|
@@ -29,15 +39,13 @@ def predict_eligibility(theory_score, practice_score):
|
|
| 29 |
# Confidence score
|
| 30 |
confidence = proba if prediction else (1 - proba)
|
| 31 |
|
| 32 |
-
# Return 3 separate values (not a dictionary)
|
| 33 |
return (
|
| 34 |
-
class_name,
|
| 35 |
-
f"{confidence * 100:.2f}%",
|
| 36 |
-
"β
Yes" if prediction else "β No"
|
| 37 |
)
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
-
# Return error message for all outputs
|
| 41 |
error_msg = f"Error: {str(e)}"
|
| 42 |
return error_msg, "0%", "β Error"
|
| 43 |
|
|
@@ -55,9 +63,9 @@ demo = gr.Interface(
|
|
| 55 |
],
|
| 56 |
title="π Eligibility Predictor",
|
| 57 |
description="Enter theory and practice scores to check eligibility.",
|
| 58 |
-
examples=[[
|
| 59 |
theme="soft"
|
| 60 |
)
|
| 61 |
|
| 62 |
# Launch
|
| 63 |
-
demo.launch(
|
|
|
|
| 4 |
import tensorflow as tf
|
| 5 |
from tensorflow import keras
|
| 6 |
from sklearn.preprocessing import StandardScaler
|
| 7 |
+
import joblib # Changed from pickle to joblib
|
| 8 |
+
import os
|
| 9 |
+
import warnings
|
| 10 |
|
| 11 |
+
# Suppress TensorFlow and CUDA warnings
|
| 12 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
| 13 |
+
warnings.filterwarnings('ignore')
|
| 14 |
+
tf.get_logger().setLevel('ERROR')
|
| 15 |
+
|
| 16 |
+
# Load model and scaler
|
| 17 |
+
try:
|
| 18 |
+
model = keras.models.load_model('eligibility_predictor.h5')
|
| 19 |
+
scaler = joblib.load('scaler.pkl') # Using joblib instead of pickle
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"Error loading model/scaler: {e}")
|
| 22 |
+
raise
|
| 23 |
|
| 24 |
def predict_eligibility(theory_score, practice_score):
|
| 25 |
"""Predicts eligibility given theory and practice scores."""
|
| 26 |
try:
|
| 27 |
+
# Preprocess input
|
| 28 |
input_df = pd.DataFrame({
|
| 29 |
'theory': [theory_score],
|
| 30 |
'practice': [practice_score]
|
|
|
|
| 39 |
# Confidence score
|
| 40 |
confidence = proba if prediction else (1 - proba)
|
| 41 |
|
|
|
|
| 42 |
return (
|
| 43 |
+
class_name,
|
| 44 |
+
f"{confidence * 100:.2f}%",
|
| 45 |
+
"β
Yes" if prediction else "β No"
|
| 46 |
)
|
| 47 |
|
| 48 |
except Exception as e:
|
|
|
|
| 49 |
error_msg = f"Error: {str(e)}"
|
| 50 |
return error_msg, "0%", "β Error"
|
| 51 |
|
|
|
|
| 63 |
],
|
| 64 |
title="π Eligibility Predictor",
|
| 65 |
description="Enter theory and practice scores to check eligibility.",
|
| 66 |
+
examples=[[10, 15], [5, 10], [15, 25]], # Adjusted examples to match your slider ranges
|
| 67 |
theme="soft"
|
| 68 |
)
|
| 69 |
|
| 70 |
# Launch
|
| 71 |
+
demo.launch()
|