Spaces:
Sleeping
Sleeping
Update app_improved.py
Browse files- app_improved.py +47 -1
app_improved.py
CHANGED
|
@@ -377,7 +377,53 @@ with gr.Blocks(title="π― Telco Churn Predictor - 93% AUC Production Model", th
|
|
| 377 |
""")
|
| 378 |
|
| 379 |
# Footer
|
| 380 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
predict_btn.click(
|
| 382 |
predict_csv,
|
| 383 |
inputs=[csv_file],
|
|
|
|
| 377 |
""")
|
| 378 |
|
| 379 |
# Footer
|
| 380 |
+
# Define all UI elements first
|
| 381 |
+
with gr.Tabs() as tabs:
|
| 382 |
+
# Batch Processing Tab
|
| 383 |
+
with gr.TabItem("π **Batch Customer Analysis**", id=0):
|
| 384 |
+
with gr.Row():
|
| 385 |
+
with gr.Column(scale=2):
|
| 386 |
+
csv_file = gr.File(label="π Upload Customer Data (CSV)", file_types=[".csv"])
|
| 387 |
+
with gr.Row():
|
| 388 |
+
predict_btn = gr.Button("π Analyze Customers", variant="primary")
|
| 389 |
+
sample_btn = gr.Button("π₯ Download Sample CSV")
|
| 390 |
+
summary = gr.Textbox(label="π Analysis Summary", interactive=False, lines=4)
|
| 391 |
+
output_file = gr.File(label="πΎ Download Predictions", visible=False)
|
| 392 |
+
with gr.Column():
|
| 393 |
+
plot1 = gr.Plot(label="π Churn Risk Distribution")
|
| 394 |
+
plot2 = gr.Plot(label="π Feature Importance")
|
| 395 |
+
|
| 396 |
+
# Single Prediction Tab
|
| 397 |
+
with gr.TabItem("π€ Single Customer Prediction", id=1):
|
| 398 |
+
with gr.Row():
|
| 399 |
+
with gr.Column(scale=1):
|
| 400 |
+
gr.Markdown("### π Customer Details")
|
| 401 |
+
with gr.Row():
|
| 402 |
+
with gr.Column():
|
| 403 |
+
account_length = gr.Slider(0, 250, 100, label="Account Length (days)")
|
| 404 |
+
custserv_calls = gr.Slider(0, 10, 0, label="Customer Service Calls")
|
| 405 |
+
total_day_minutes = gr.Slider(0, 400, 200, label="Day Minutes")
|
| 406 |
+
total_day_calls = gr.Slider(0, 200, 100, label="Day Calls")
|
| 407 |
+
total_eve_minutes = gr.Slider(0, 400, 200, label="Evening Minutes")
|
| 408 |
+
with gr.Column():
|
| 409 |
+
total_eve_calls = gr.Slider(0, 200, 100, label="Evening Calls")
|
| 410 |
+
total_night_minutes = gr.Slider(0, 400, 200, label="Night Minutes")
|
| 411 |
+
total_night_calls = gr.Slider(0, 200, 100, label="Night Calls")
|
| 412 |
+
total_intl_minutes = gr.Slider(0, 30, 10, label="International Minutes")
|
| 413 |
+
total_intl_calls = gr.Slider(0, 20, 3, label="International Calls")
|
| 414 |
+
with gr.Row():
|
| 415 |
+
number_vmail_messages = gr.Slider(0, 100, 0, label="Voicemail Messages")
|
| 416 |
+
international_plan = gr.Radio(["Yes", "No"], label="International Plan", value="No")
|
| 417 |
+
voice_mail_plan = gr.Radio(["Yes", "No"], label="Voicemail Plan", value="No")
|
| 418 |
+
|
| 419 |
+
predict_btn_single = gr.Button("π Predict Churn Risk", variant="primary")
|
| 420 |
+
|
| 421 |
+
with gr.Column(scale=1):
|
| 422 |
+
result = gr.Markdown("## π― Churn Risk: **Not Analyzed**")
|
| 423 |
+
gauge = gr.Plot(label="Churn Risk Score")
|
| 424 |
+
importance = gr.Plot(label="Top Factors")
|
| 425 |
+
|
| 426 |
+
# Event handlers
|
| 427 |
predict_btn.click(
|
| 428 |
predict_csv,
|
| 429 |
inputs=[csv_file],
|