Spaces:
No application file
No application file
Download Apps.py from ahmad092/Decision_Tree_Classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/ahmad092/Decision_Tree_Classifier/resolve/main/Apps.py
- Command line
-
hf download hf://spaces/ahmad092/Decision_Tree_Classifier/Apps.py
-
curl -L -o Apps.py https://huggingface.co/spaces/ahmad092/Decision_Tree_Classifier/resolve/main/Apps.py
1.02 kB
| import gradio as gr | |
| import pandas as pd | |
| import joblib | |
| import numpy as np | |
| # 1. Load the model | |
| model = joblib.load('model.pkl') | |
| # 2. Define the prediction function | |
| def predict_churn(age, tenure, balance, salary): | |
| # Prepare the input in the same format as your training data X | |
| input_data = np.array([[age, tenure, balance, salary]]) | |
| # Get prediction | |
| prediction = model.predict(input_data) | |
| # Return human-readable result | |
| return "Likely to EXIT" if prediction[0] == 1 else "Likely to STAY" | |
| # 3. Create the Gradio Interface | |
| demo = gr.Interface( | |
| fn=predict_churn, | |
| inputs=[ | |
| gr.Number(label="Age (Years)"), | |
| gr.Slider(0, 10, step=1, label="Tenure (Years)"), | |
| gr.Number(label="Account Balance"), | |
| gr.Number(label="Estimated Annual Salary") | |
| ], | |
| outputs="text", | |
| title="Customer Churn Predictor", | |
| description="This model uses a Decision Tree (Optimized) to predict customer retention." | |
| ) | |
| # 4. Launch | |
| if __name__ == "__main__": | |
| demo.launch() |