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, LabelEncoder import pickle # Missing import # Load model and preprocessing objects (replace paths if needed) model = keras.models.load_model('model.h5') with open('scaler.pkl', 'rb') as f: scaler = pickle.load(f) with open('label_encoder.pkl', 'rb') as f: label_encoder = 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 = label_encoder.inverse_transform([prediction])[0] # 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 "❌ No" if prediction else "✅ Yes" # 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, 100, value=50, step=1, label="Theory Score"), gr.Slider(0, 100, value=60, step=1, label="Practice Score") ], outputs=[ gr.Textbox(label="Prediction"), # Changed from gr.Label to gr.Textbox 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)