import gradio as gr import pandas as pd import numpy as np import tensorflow as tf from tensorflow import keras from sklearn.preprocessing import StandardScaler import pickle # Load model and scaler (replace paths if needed) model = keras.models.load_model('eligibility_predictor.h5') # Changed to match your saved model name with open('scaler.pkl', 'rb') as f: scaler = pickle.load(f) def predict_eligibility(theory_score, practice_score): """Predicts eligibility given theory and practice scores.""" try: # Preprocess input - create DataFrame to avoid feature name warning input_df = pd.DataFrame({ 'theory': [theory_score], 'practice': [practice_score] }) scaled_input = scaler.transform(input_df) # Predict proba = model.predict(scaled_input, verbose=0)[0][0] prediction = int(proba > 0.5) class_name = "Eligible" if prediction else "Not eligible" # Confidence score confidence = proba if prediction else (1 - proba) # Return 3 separate values (not a dictionary) return ( class_name, # First output: Prediction label f"{confidence * 100:.2f}%", # Second output: Confidence "✅ Yes" if prediction else "❌ No" # Third output: Eligibility status ) except Exception as e: # Return error message for all outputs error_msg = f"Error: {str(e)}" return error_msg, "0%", "❌ Error" # Gradio Interface demo = gr.Interface( fn=predict_eligibility, inputs=[ gr.Slider(0, 20, value=0, step=1, label="Theory Score"), gr.Slider(0, 30, value=0, step=1, label="Practice Score") ], outputs=[ gr.Textbox(label="Prediction"), gr.Textbox(label="Confidence"), gr.Textbox(label="Eligibility Status") ], title="🎓 Eligibility Predictor", description="Enter theory and practice scores to check eligibility.", examples=[[85, 90], [45, 60], [70, 75]], theme="soft" ) # Launch demo.launch(share=True)