sammy786 commited on
Commit
44ce110
·
verified ·
1 Parent(s): 05eca86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -48
app.py CHANGED
@@ -1106,19 +1106,19 @@ Get AI-powered credit card recommendations that maximize your rewards based on:
1106
  value="""
1107
  <div style="display: flex; gap: 10px; flex-wrap: wrap;">
1108
  <div class="metric-card" style="flex: 1; min-width: 200px;">
1109
- <h2>$342</h2>
1110
  <p>💰 Potential Annual Savings</p>
1111
  </div>
1112
  <div class="metric-card metric-card-green" style="flex: 1; min-width: 200px;">
1113
- <h2>23%</h2>
1114
  <p>📈 Rewards Rate Increase</p>
1115
  </div>
1116
  <div class="metric-card metric-card-orange" style="flex: 1; min-width: 200px;">
1117
- <h2>156</h2>
1118
  <p>✅ Optimized Transactions</p>
1119
  </div>
1120
  <div class="metric-card metric-card-blue" style="flex: 1; min-width: 200px;">
1121
- <h2>87/100</h2>
1122
  <p>⭐ Optimization Score</p>
1123
  </div>
1124
  </div>
@@ -1150,65 +1150,81 @@ Get AI-powered credit card recommendations that maximize your rewards based on:
1150
  with gr.Column(scale=1):
1151
  gr.Markdown("### 💰 Category Spending Breakdown")
1152
  spending_table = gr.Markdown(
1153
- value="""
1154
- | Category | Monthly Spend | Best Card | Rewards | Rate |
1155
- |----------|---------------|-----------|---------|------|
1156
- | 🛒 Groceries | $450.00 | Amex Gold | $27.00 | 6% |
1157
- | 🍽️ Restaurants | $320.00 | Amex Gold | $12.80 | 4% |
1158
- | ⛽ Gas | $180.00 | Costco Visa | $7.20 | 4% |
1159
- | ✈️ Travel | $850.00 | Sapphire Reserve | $42.50 | 5% |
1160
- | 🎬 Entertainment | $125.00 | Freedom Unlimited | $1.88 | 1.5% |
1161
- | 🏪 Online Shopping | $280.00 | Amazon Prime | $16.80 | 6% |
1162
- | **Total** | **$2,205.00** | - | **$108.18** | **4.9%** |
1163
- """
1164
  )
1165
 
1166
  with gr.Column(scale=1):
1167
  gr.Markdown("### 📈 Monthly Trends & Insights")
1168
  insights_display = gr.Markdown(
1169
- value="""
1170
- **🔥 Top Spending Categories:**
1171
- 1. ✈️ Travel: $850 (↑ 45% from last month)
1172
- 2. 🛒 Groceries: $450 (↑ 12%)
1173
- 3. 🍽️ Restaurants: $320 (↓ 5%)
1174
-
1175
- **💡 Optimization Opportunities:**
1176
- - ✅ You're using optimal cards 87% of the time
1177
- - 🎯 Switch to Chase Freedom for Q4 5% grocery bonus
1178
- - ⚠️ Amex Gold dining cap approaching ($2,000 limit)
1179
-
1180
- **🏆 Best Performing Card:**
1181
- Chase Sapphire Reserve - $42.50 rewards earned
1182
-
1183
- **📊 Year-to-Date:**
1184
- - Total Rewards: $1,298.16
1185
- - Potential if optimized: $1,640.00
1186
- - **Money left on table: $341.84**
1187
- """
1188
  )
1189
 
1190
  gr.Markdown("---")
1191
 
1192
  forecast_display = gr.Markdown(
1193
- value="""
1194
- ### 🔮 Next Month Forecast
1195
-
1196
- Based on your spending patterns:
1197
- - **Predicted Spend:** $2,350
1198
- - **Predicted Rewards:** $115.25
1199
- - **Cards to Watch:** Amex Gold (dining cap), Freedom (quarterly bonus)
1200
-
1201
- **Recommendations:**
1202
- 1. 💳 Use Chase Freedom for groceries in Q4 (5% back)
1203
- 2. ⚠️ Monitor Amex Gold dining spend (cap at $2,000)
1204
- 3. 🎯 Book holiday travel with Sapphire Reserve for 5x points
1205
- """
1206
  )
1207
 
1208
  analytics_status = gr.Markdown(
1209
- value="*Analytics loaded for u_alice*",
1210
  elem_classes=["status-text"]
1211
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1212
 
1213
  def update_analytics_with_charts(user_id: str):
1214
  """Fetch and format analytics with charts for selected user"""
 
1106
  value="""
1107
  <div style="display: flex; gap: 10px; flex-wrap: wrap;">
1108
  <div class="metric-card" style="flex: 1; min-width: 200px;">
1109
+ <h2>$0</h2>
1110
  <p>💰 Potential Annual Savings</p>
1111
  </div>
1112
  <div class="metric-card metric-card-green" style="flex: 1; min-width: 200px;">
1113
+ <h2>0%</h2>
1114
  <p>📈 Rewards Rate Increase</p>
1115
  </div>
1116
  <div class="metric-card metric-card-orange" style="flex: 1; min-width: 200px;">
1117
+ <h2>0</h2>
1118
  <p>✅ Optimized Transactions</p>
1119
  </div>
1120
  <div class="metric-card metric-card-blue" style="flex: 1; min-width: 200px;">
1121
+ <h2>0/100</h2>
1122
  <p>⭐ Optimization Score</p>
1123
  </div>
1124
  </div>
 
1150
  with gr.Column(scale=1):
1151
  gr.Markdown("### 💰 Category Spending Breakdown")
1152
  spending_table = gr.Markdown(
1153
+ value="*Loading data...*"
 
 
 
 
 
 
 
 
 
 
1154
  )
1155
 
1156
  with gr.Column(scale=1):
1157
  gr.Markdown("### 📈 Monthly Trends & Insights")
1158
  insights_display = gr.Markdown(
1159
+ value="*Loading insights...*"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1160
  )
1161
 
1162
  gr.Markdown("---")
1163
 
1164
  forecast_display = gr.Markdown(
1165
+ value="*Loading forecast...*"
 
 
 
 
 
 
 
 
 
 
 
 
1166
  )
1167
 
1168
  analytics_status = gr.Markdown(
1169
+ value="*Select a user to view analytics*",
1170
  elem_classes=["status-text"]
1171
  )
1172
+
1173
+ # ========== ADD EVENT HANDLERS HERE ==========
1174
+
1175
+ # When user changes dropdown
1176
+ analytics_user.change(
1177
+ fn=update_analytics_with_charts,
1178
+ inputs=[analytics_user],
1179
+ outputs=[
1180
+ metrics_display,
1181
+ spending_chart,
1182
+ optimization_gauge,
1183
+ rewards_pie_chart,
1184
+ card_performance_chart,
1185
+ trend_chart,
1186
+ spending_table,
1187
+ insights_display,
1188
+ forecast_display,
1189
+ analytics_status
1190
+ ]
1191
+ )
1192
+
1193
+ # When refresh button is clicked
1194
+ refresh_analytics_btn.click(
1195
+ fn=update_analytics_with_charts,
1196
+ inputs=[analytics_user],
1197
+ outputs=[
1198
+ metrics_display,
1199
+ spending_chart,
1200
+ optimization_gauge,
1201
+ rewards_pie_chart,
1202
+ card_performance_chart,
1203
+ trend_chart,
1204
+ spending_table,
1205
+ insights_display,
1206
+ forecast_display,
1207
+ analytics_status
1208
+ ]
1209
+ )
1210
+
1211
+ # Load initial data when app starts
1212
+ app.load(
1213
+ fn=update_analytics_with_charts,
1214
+ inputs=[analytics_user],
1215
+ outputs=[
1216
+ metrics_display,
1217
+ spending_chart,
1218
+ optimization_gauge,
1219
+ rewards_pie_chart,
1220
+ card_performance_chart,
1221
+ trend_chart,
1222
+ spending_table,
1223
+ insights_display,
1224
+ forecast_display,
1225
+ analytics_status
1226
+ ]
1227
+ )
1228
 
1229
  def update_analytics_with_charts(user_id: str):
1230
  """Fetch and format analytics with charts for selected user"""