Spaces:
Sleeping
Sleeping
Update please
#2
by
shubhhammm
- opened
app.py
CHANGED
|
@@ -18,26 +18,17 @@ def app():
|
|
| 18 |
scaler = load_scaler('models/scaler.pkl')
|
| 19 |
|
| 20 |
cluster_plans = {
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
}
|
| 30 |
|
| 31 |
def get_plan_recommendation(cluster):
|
| 32 |
-
"""
|
| 33 |
-
Given a cluster number, returns the recommended subscription plan.
|
| 34 |
-
|
| 35 |
-
Parameters:
|
| 36 |
-
cluster (int): The cluster number the user belongs to.
|
| 37 |
-
|
| 38 |
-
Returns:
|
| 39 |
-
str: The recommended subscription plan.
|
| 40 |
-
"""
|
| 41 |
if cluster in cluster_plans:
|
| 42 |
return cluster_plans[cluster]
|
| 43 |
else:
|
|
@@ -91,9 +82,10 @@ def app():
|
|
| 91 |
return tsne_plot, f"Predicted Churn Percentage: {churn_percentage:.2f}%"
|
| 92 |
|
| 93 |
with gr.Blocks() as app:
|
| 94 |
-
|
|
|
|
| 95 |
with gr.Group():
|
| 96 |
-
gr.Markdown("## Churn Prediction App")
|
| 97 |
age = gr.Slider(label="Age", minimum=18, maximum=100, step=1, value=30)
|
| 98 |
gender = gr.Dropdown(label="Gender", choices=["Male", "Female"], value="Male")
|
| 99 |
location = gr.Dropdown(label="Location", choices=["Urban", "Rural", "Suburban"], value="Urban")
|
|
@@ -107,7 +99,7 @@ def app():
|
|
| 107 |
base_charge = gr.Slider(label="Base Charge", minimum=10, maximum=500, step=1, value=30)
|
| 108 |
|
| 109 |
with gr.Group():
|
| 110 |
-
gr.Markdown("## Results")
|
| 111 |
predicted_group = gr.Text(label="Predicted Group")
|
| 112 |
predicted_churn = gr.Text(label="Predicted Churn")
|
| 113 |
suggested_plan = gr.Text(label="Suggested Plan")
|
|
@@ -115,6 +107,32 @@ def app():
|
|
| 115 |
predict_button = gr.Button("Predict")
|
| 116 |
predict_button.click(predict, inputs=[age, gender, location, subscription_length, monthly_bill, avg_internet_usage, num_tickets, avg_talktime, social_class, subscription_type, base_charge], outputs=[predicted_group, predicted_churn, suggested_plan])
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
with gr.Tab("Upload CSV"):
|
| 119 |
with gr.Group():
|
| 120 |
gr.Markdown("## Upload CSV for Analysis")
|
|
@@ -131,4 +149,4 @@ def app():
|
|
| 131 |
app.launch()
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|
| 134 |
-
app()
|
|
|
|
| 18 |
scaler = load_scaler('models/scaler.pkl')
|
| 19 |
|
| 20 |
cluster_plans = {
|
| 21 |
+
0: "Premium Subscription",
|
| 22 |
+
1: "Basic Subscription",
|
| 23 |
+
2: "Family Plan",
|
| 24 |
+
3: "Small Business Plan",
|
| 25 |
+
4: "Unlimited Usage Plan",
|
| 26 |
+
5: "Student Discount Plan",
|
| 27 |
+
6: "Senior Citizen Plan",
|
| 28 |
+
7: "Power User Plan"
|
| 29 |
}
|
| 30 |
|
| 31 |
def get_plan_recommendation(cluster):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
if cluster in cluster_plans:
|
| 33 |
return cluster_plans[cluster]
|
| 34 |
else:
|
|
|
|
| 82 |
return tsne_plot, f"Predicted Churn Percentage: {churn_percentage:.2f}%"
|
| 83 |
|
| 84 |
with gr.Blocks() as app:
|
| 85 |
+
# First Churn Prediction Tab
|
| 86 |
+
with gr.Tab("Churn Prediction 1"):
|
| 87 |
with gr.Group():
|
| 88 |
+
gr.Markdown("## Churn Prediction App 1")
|
| 89 |
age = gr.Slider(label="Age", minimum=18, maximum=100, step=1, value=30)
|
| 90 |
gender = gr.Dropdown(label="Gender", choices=["Male", "Female"], value="Male")
|
| 91 |
location = gr.Dropdown(label="Location", choices=["Urban", "Rural", "Suburban"], value="Urban")
|
|
|
|
| 99 |
base_charge = gr.Slider(label="Base Charge", minimum=10, maximum=500, step=1, value=30)
|
| 100 |
|
| 101 |
with gr.Group():
|
| 102 |
+
gr.Markdown("## Results 1")
|
| 103 |
predicted_group = gr.Text(label="Predicted Group")
|
| 104 |
predicted_churn = gr.Text(label="Predicted Churn")
|
| 105 |
suggested_plan = gr.Text(label="Suggested Plan")
|
|
|
|
| 107 |
predict_button = gr.Button("Predict")
|
| 108 |
predict_button.click(predict, inputs=[age, gender, location, subscription_length, monthly_bill, avg_internet_usage, num_tickets, avg_talktime, social_class, subscription_type, base_charge], outputs=[predicted_group, predicted_churn, suggested_plan])
|
| 109 |
|
| 110 |
+
# Second Churn Prediction Tab
|
| 111 |
+
with gr.Tab("Churn Prediction 2"):
|
| 112 |
+
with gr.Group():
|
| 113 |
+
gr.Markdown("## Churn Prediction App 2")
|
| 114 |
+
age_dup = gr.Slider(label="Age", minimum=18, maximum=100, step=1, value=30)
|
| 115 |
+
gender_dup = gr.Dropdown(label="Gender", choices=["Male", "Female"], value="Male")
|
| 116 |
+
location_dup = gr.Dropdown(label="Location", choices=["Urban", "Rural", "Suburban"], value="Urban")
|
| 117 |
+
subscription_length_dup = gr.Slider(label="Subscription Length (Months)", minimum=1, maximum=60, step=1, value=12)
|
| 118 |
+
monthly_bill_dup = gr.Slider(label="Monthly Bill", minimum=10, maximum=1000, step=1, value=50)
|
| 119 |
+
avg_internet_usage_dup = gr.Slider(label="Average Internet Usage", minimum=1, maximum=200, step=1, value=50)
|
| 120 |
+
num_tickets_dup = gr.Slider(label="Number of Tickets", minimum=0, maximum=20, step=1, value=2)
|
| 121 |
+
avg_talktime_dup = gr.Slider(label="Average Talktime Usage", minimum=1, maximum=200, step=1, value=50)
|
| 122 |
+
social_class_dup = gr.Slider(label="Social Class", minimum=1, maximum=3, step=1, value=1)
|
| 123 |
+
subscription_type_dup = gr.Dropdown(label="Subscription Type", choices=["A", "B", "C", "D", "E"], value="B")
|
| 124 |
+
base_charge_dup = gr.Slider(label="Base Charge", minimum=10, maximum=500, step=1, value=30)
|
| 125 |
+
|
| 126 |
+
with gr.Group():
|
| 127 |
+
gr.Markdown("## Results 2")
|
| 128 |
+
predicted_group_dup = gr.Text(label="Predicted Group (Duplicate)")
|
| 129 |
+
predicted_churn_dup = gr.Text(label="Predicted Churn (Duplicate)")
|
| 130 |
+
suggested_plan_dup = gr.Text(label="Suggested Plan (Duplicate)")
|
| 131 |
+
|
| 132 |
+
predict_button_dup = gr.Button("Predict (Duplicate)")
|
| 133 |
+
predict_button_dup.click(predict, inputs=[age_dup, gender_dup, location_dup, subscription_length_dup, monthly_bill_dup, avg_internet_usage_dup, num_tickets_dup, avg_talktime_dup, social_class_dup, subscription_type_dup, base_charge_dup], outputs=[predicted_group_dup, predicted_churn_dup, suggested_plan_dup])
|
| 134 |
+
|
| 135 |
+
# Upload CSV Tab
|
| 136 |
with gr.Tab("Upload CSV"):
|
| 137 |
with gr.Group():
|
| 138 |
gr.Markdown("## Upload CSV for Analysis")
|
|
|
|
| 149 |
app.launch()
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
| 152 |
+
app()
|