Update app.py
Browse files
app.py
CHANGED
|
@@ -648,34 +648,47 @@ def query_with_llm(request: QueryRequest):
|
|
| 648 |
return 0
|
| 649 |
|
| 650 |
context = f"""
|
| 651 |
-
You are
|
| 652 |
|
| 653 |
-
|
| 654 |
-
International Users: {int(safe_col_count('intl_total_calls', 0)):,}
|
| 655 |
|
| 656 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 657 |
- Total Calls: {safe_col_sum('voice_total_calls'):,.0f}
|
| 658 |
- Total Duration: {safe_col_sum('voice_total_duration_mins'):,.0f} mins
|
| 659 |
-
- Average per User: {safe_col_mean('voice_total_calls'):.1f} calls
|
| 660 |
|
| 661 |
-
{'Time Distribution:' if 'voice_morning_calls' in df.columns else ''}
|
| 662 |
-
{f"- Morning
|
| 663 |
-
{f"- Evening
|
| 664 |
-
{f"- Night
|
| 665 |
|
| 666 |
-
{'SMS:' if 'sms_total_messages' in df.columns else ''}
|
| 667 |
{f"- Total Messages: {safe_col_sum('sms_total_messages'):,.0f}" if 'sms_total_messages' in df.columns else ''}
|
| 668 |
-
{f"- Average per User: {safe_col_mean('sms_total_messages'):.1f}" if 'sms_total_messages' in df.columns else ''}
|
| 669 |
-
|
| 670 |
-
Data Usage:
|
| 671 |
-
- Total Data (
|
| 672 |
-
- Average per User
|
| 673 |
-
{f"- Total Download
|
| 674 |
-
{f"- Total Upload
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 679 |
"""
|
| 680 |
|
| 681 |
try:
|
|
|
|
| 648 |
return 0
|
| 649 |
|
| 650 |
context = f"""
|
| 651 |
+
You are a telecom analytics AI assistant analyzing customer data. Provide clear, actionable insights.
|
| 652 |
|
| 653 |
+
CUSTOMER DATABASE STATISTICS:
|
|
|
|
| 654 |
|
| 655 |
+
π Overview:
|
| 656 |
+
- Total Customers: {len(df):,}
|
| 657 |
+
- International Users: {int(safe_col_count('intl_total_calls', 0)):,} ({safe_col_count('intl_total_calls', 0)/len(df)*100:.1f}%)
|
| 658 |
+
|
| 659 |
+
π Voice Communication:
|
| 660 |
- Total Calls: {safe_col_sum('voice_total_calls'):,.0f}
|
| 661 |
- Total Duration: {safe_col_sum('voice_total_duration_mins'):,.0f} mins
|
| 662 |
+
- Average per User: {safe_col_mean('voice_total_calls'):.1f} calls, {safe_col_mean('voice_total_duration_mins'):.1f} mins
|
| 663 |
|
| 664 |
+
{'π
Time Distribution:' if 'voice_morning_calls' in df.columns else ''}
|
| 665 |
+
{f"- Morning (6am-12pm): {safe_col_sum('voice_morning_calls'):,.0f} calls" if 'voice_morning_calls' in df.columns else ''}
|
| 666 |
+
{f"- Evening (12pm-6pm): {safe_col_sum('voice_evening_calls'):,.0f} calls" if 'voice_evening_calls' in df.columns else ''}
|
| 667 |
+
{f"- Night (6pm-6am): {safe_col_sum('voice_night_calls'):,.0f} calls" if 'voice_night_calls' in df.columns else ''}
|
| 668 |
|
| 669 |
+
{'π¬ SMS:' if 'sms_total_messages' in df.columns else ''}
|
| 670 |
{f"- Total Messages: {safe_col_sum('sms_total_messages'):,.0f}" if 'sms_total_messages' in df.columns else ''}
|
| 671 |
+
{f"- Average per User: {safe_col_mean('sms_total_messages'):.1f} messages" if 'sms_total_messages' in df.columns else ''}
|
| 672 |
+
|
| 673 |
+
π Data Usage:
|
| 674 |
+
- Total Data: {safe_col_sum('data_total_mb'):,.0f} MB ({safe_col_sum('data_total_mb')/1024:.1f} GB)
|
| 675 |
+
- Average per User: {safe_col_mean('data_total_mb'):.1f} MB
|
| 676 |
+
{f"- Total Download: {safe_col_sum('data_downlink_mb') / 1024:.1f} GB" if 'data_downlink_mb' in df.columns else ''}
|
| 677 |
+
{f"- Total Upload: {safe_col_sum('data_uplink_mb') / 1024:.1f} GB" if 'data_uplink_mb' in df.columns else ''}
|
| 678 |
+
|
| 679 |
+
---
|
| 680 |
+
|
| 681 |
+
USER QUESTION: {request.question}
|
| 682 |
+
|
| 683 |
+
INSTRUCTIONS:
|
| 684 |
+
- If asked for package recommendations, provide structured response with:
|
| 685 |
+
1. USAGE PROFILE (analyze their patterns)
|
| 686 |
+
2. RECOMMENDED PACKAGE (specific details)
|
| 687 |
+
3. KEY BENEFITS (3-4 points)
|
| 688 |
+
4. PRICING STRATEGY (upsell/retention approach)
|
| 689 |
+
- Use data-driven insights from statistics above
|
| 690 |
+
- Be specific with numbers and percentages
|
| 691 |
+
- Keep response concise but actionable
|
| 692 |
"""
|
| 693 |
|
| 694 |
try:
|