Devavrat28 commited on
Commit
f0a46fe
ยท
verified ยท
1 Parent(s): 76e0b39

Updated app.

Browse files
Files changed (1) hide show
  1. app.py +398 -98
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py - Optimized with better timeout handling
2
  import gradio as gr
3
  import requests
4
  import json
@@ -192,111 +192,411 @@ def test_service():
192
  except Exception as e:
193
  return f"โŒ **Test Error**: {str(e)}"
194
 
195
- with gr.Blocks(
196
- theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"),
197
- title="๐Ÿ“ˆ Personal Finance Strategist",
198
- css="""
199
- .gradio-container {
200
- max-width: 1200px !important;
201
- }
202
- .status-box {
203
- padding: 10px;
204
- border-radius: 8px;
205
- margin: 10px 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  }
207
- .sticky-btn {
208
- position: sticky;
209
- top: 0;
210
- z-index: 10;
211
- background: white;
212
- padding: 5px;
213
  }
214
- """
215
- ) as interface:
216
 
217
- gr.Markdown(
218
- """
219
- # ๐Ÿ“ˆ Personal Finance Strategist
220
- **AI-Powered Investment Strategy Generator**
221
- """
222
- )
223
 
224
- with gr.Accordion("๐Ÿ‘ค Personal + Financial Profile", open=True):
225
- with gr.Row():
226
- with gr.Column():
227
- age_group = gr.Dropdown(
228
- choices=["20s", "30s", "40s", "50s+"],
229
- label="Age Group",
230
- value="30s",
231
- info="Select your current age range"
232
- )
233
- country = gr.Dropdown(
234
- choices=[
235
- "United States", "Canada", "United Kingdom",
236
- "Germany", "France", "Italy", "Japan", "India"
237
- ],
238
- label="Country of Residence",
239
- value="United States",
240
- info="Your tax residence country"
241
- )
242
- income = gr.Number(
243
- label="Monthly Income ($)",
244
- value=6000,
245
- minimum=0,
246
- info="Your total monthly income before taxes"
247
- )
248
- expenses = gr.Number(
249
- label="Monthly Expenses ($)",
250
- value=4000,
251
- minimum=0,
252
- info="Your total monthly expenses"
253
- )
254
 
255
- with gr.Column():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  risk_profile = gr.Radio(
257
- choices=["Conservative", "Moderate", "Aggressive"],
258
- label="Risk Tolerance",
259
- value="Moderate",
260
- info="How comfortable are you with investment risk?",
261
- interactive=True
262
- )
263
- goal = gr.Textbox(
264
- label="Financial Goal",
265
- placeholder="e.g., buy a house, retirement, emergency fund, child's education",
266
- info="What are you saving/investing for?"
267
  )
268
- timeframe = gr.Textbox(
269
- label="Investment Timeframe",
270
- placeholder="e.g., 5 years, 10 years, until retirement",
271
- info="How long do you plan to invest?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  )
273
 
274
- with gr.Row():
275
- submit_btn = gr.Button("๐Ÿš€ Generate Investment Strategy", variant="primary", size="lg")
276
- test_btn = gr.Button("๐Ÿ” Test Service", variant="secondary", size="lg")
277
-
278
- gr.Markdown("### ๐Ÿ’ก Tips for best results")
279
- gr.HTML("""
280
- <ul style="line-height: 1.6">
281
- <li>โœ… Be specific about your financial goal</li>
282
- <li>โณ Include realistic timeframes</li>
283
- <li>๐Ÿ“‰ Consider your actual risk tolerance</li>
284
- <li>๐Ÿ’ต Ensure income is greater than expenses</li>
285
- <li>๐ŸŒ Country selection affects tax-advantaged advice</li>
286
- </ul>
287
- """)
288
-
289
- with gr.Box():
290
- output = gr.Markdown(
291
- label="๐Ÿ“Š Investment Strategy",
292
- value="๐Ÿง  Click 'Generate Investment Strategy' to get personalized recommendations!",
293
- )
294
-
295
- # Optional image upload panel (currently not used in logic)
296
- with gr.Accordion("๐Ÿ–ผ๏ธ Upload a financial-related image (optional - future feature)", open=False):
297
- img = gr.Image(label="Upload Chart or Statement", type="filepath")
298
-
299
- # Attach event handlers
300
  submit_btn.click(
301
  fn=get_investment_strategy,
302
  inputs=[age_group, income, expenses, risk_profile, goal, timeframe, country],
@@ -317,4 +617,4 @@ if __name__ == "__main__":
317
  share=False,
318
  show_error=True,
319
  debug=True
320
- )
 
1
+ # app.py - Enhanced Professional UI
2
  import gradio as gr
3
  import requests
4
  import json
 
192
  except Exception as e:
193
  return f"โŒ **Test Error**: {str(e)}"
194
 
195
+ # Enhanced professional CSS styling
196
+ custom_css = """
197
+ /* Global container styling */
198
+ .gradio-container {
199
+ max-width: 1400px !important;
200
+ margin: 0 auto !important;
201
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
202
+ min-height: 100vh;
203
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
204
+ }
205
+
206
+ /* Main content area */
207
+ .main-content {
208
+ background: rgba(255, 255, 255, 0.95) !important;
209
+ backdrop-filter: blur(20px) !important;
210
+ border-radius: 20px !important;
211
+ padding: 2rem !important;
212
+ margin: 2rem !important;
213
+ box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1) !important;
214
+ border: 1px solid rgba(255, 255, 255, 0.2) !important;
215
+ }
216
+
217
+ /* Header styling */
218
+ .finance-header {
219
+ text-align: center;
220
+ background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
221
+ color: white;
222
+ padding: 3rem 2rem;
223
+ border-radius: 20px;
224
+ margin-bottom: 2rem;
225
+ position: relative;
226
+ overflow: hidden;
227
+ }
228
+
229
+ .finance-header::before {
230
+ content: "";
231
+ position: absolute;
232
+ top: 0;
233
+ left: 0;
234
+ right: 0;
235
+ bottom: 0;
236
+ background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="50" cy="50" r="0.5" fill="rgba(255,255,255,0.1)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
237
+ opacity: 0.1;
238
+ }
239
+
240
+ .finance-header h1 {
241
+ font-size: 3rem !important;
242
+ font-weight: 800 !important;
243
+ margin-bottom: 1rem !important;
244
+ background: linear-gradient(45deg, #ffffff, #e0e7ff);
245
+ -webkit-background-clip: text;
246
+ -webkit-text-fill-color: transparent;
247
+ position: relative;
248
+ z-index: 1;
249
+ }
250
+
251
+ .finance-header p {
252
+ font-size: 1.25rem !important;
253
+ opacity: 0.9 !important;
254
+ margin-bottom: 0 !important;
255
+ position: relative;
256
+ z-index: 1;
257
+ }
258
+
259
+ /* Icon styling */
260
+ .finance-icon {
261
+ font-size: 4rem;
262
+ margin-bottom: 1rem;
263
+ position: relative;
264
+ z-index: 1;
265
+ }
266
+
267
+ /* Form sections */
268
+ .form-section {
269
+ background: white !important;
270
+ border-radius: 16px !important;
271
+ padding: 2rem !important;
272
+ margin-bottom: 1.5rem !important;
273
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08) !important;
274
+ border: 1px solid rgba(255, 255, 255, 0.2) !important;
275
+ transition: all 0.3s ease !important;
276
+ }
277
+
278
+ .form-section:hover {
279
+ box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12) !important;
280
+ transform: translateY(-2px) !important;
281
+ }
282
+
283
+ .form-section h3 {
284
+ color: #1e3c72 !important;
285
+ font-weight: 700 !important;
286
+ font-size: 1.5rem !important;
287
+ margin-bottom: 1.5rem !important;
288
+ display: flex !important;
289
+ align-items: center !important;
290
+ gap: 0.75rem !important;
291
+ }
292
+
293
+ /* Input styling */
294
+ .gradio-textbox, .gradio-number, .gradio-dropdown {
295
+ border-radius: 12px !important;
296
+ border: 2px solid #e5e7eb !important;
297
+ transition: all 0.3s ease !important;
298
+ font-size: 1rem !important;
299
+ padding: 0.75rem 1rem !important;
300
+ }
301
+
302
+ .gradio-textbox:focus, .gradio-number:focus, .gradio-dropdown:focus {
303
+ border-color: #667eea !important;
304
+ box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
305
+ outline: none !important;
306
+ }
307
+
308
+ /* Button styling */
309
+ .primary-btn {
310
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
311
+ border: none !important;
312
+ border-radius: 12px !important;
313
+ padding: 1rem 2rem !important;
314
+ font-size: 1.1rem !important;
315
+ font-weight: 600 !important;
316
+ color: white !important;
317
+ transition: all 0.3s ease !important;
318
+ box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3) !important;
319
+ min-height: 56px !important;
320
+ }
321
+
322
+ .primary-btn:hover {
323
+ transform: translateY(-2px) !important;
324
+ box-shadow: 0 12px 32px rgba(102, 126, 234, 0.4) !important;
325
+ }
326
+
327
+ .secondary-btn {
328
+ background: linear-gradient(135deg, #64748b 0%, #475569 100%) !important;
329
+ border: none !important;
330
+ border-radius: 12px !important;
331
+ padding: 1rem 2rem !important;
332
+ font-size: 1.1rem !important;
333
+ font-weight: 600 !important;
334
+ color: white !important;
335
+ transition: all 0.3s ease !important;
336
+ box-shadow: 0 8px 24px rgba(100, 116, 139, 0.3) !important;
337
+ min-height: 56px !important;
338
+ }
339
+
340
+ .secondary-btn:hover {
341
+ transform: translateY(-2px) !important;
342
+ box-shadow: 0 12px 32px rgba(100, 116, 139, 0.4) !important;
343
+ }
344
+
345
+ /* Output area styling */
346
+ .output-area {
347
+ background: white !important;
348
+ border-radius: 16px !important;
349
+ padding: 2rem !important;
350
+ margin-top: 2rem !important;
351
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08) !important;
352
+ border: 1px solid rgba(255, 255, 255, 0.2) !important;
353
+ min-height: 200px !important;
354
+ }
355
+
356
+ /* Tips section */
357
+ .tips-section {
358
+ background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%) !important;
359
+ border-radius: 16px !important;
360
+ padding: 2rem !important;
361
+ margin: 2rem 0 !important;
362
+ border-left: 4px solid #667eea !important;
363
+ }
364
+
365
+ .tips-section h4 {
366
+ color: #1e3c72 !important;
367
+ font-weight: 700 !important;
368
+ margin-bottom: 1rem !important;
369
+ }
370
+
371
+ /* Radio button styling */
372
+ .gradio-radio {
373
+ gap: 1rem !important;
374
+ }
375
+
376
+ .gradio-radio label {
377
+ background: white !important;
378
+ border: 2px solid #e5e7eb !important;
379
+ border-radius: 12px !important;
380
+ padding: 1rem !important;
381
+ transition: all 0.3s ease !important;
382
+ cursor: pointer !important;
383
+ }
384
+
385
+ .gradio-radio label:hover {
386
+ border-color: #667eea !important;
387
+ background: #f8fafc !important;
388
+ }
389
+
390
+ .gradio-radio input:checked + label {
391
+ border-color: #667eea !important;
392
+ background: linear-gradient(135deg, #667eea10, #764ba210) !important;
393
+ color: #1e3c72 !important;
394
+ }
395
+
396
+ /* Progress indicator */
397
+ .loading-indicator {
398
+ background: linear-gradient(90deg, #667eea, #764ba2, #667eea) !important;
399
+ background-size: 200% 100% !important;
400
+ animation: gradient 2s ease infinite !important;
401
+ }
402
+
403
+ @keyframes gradient {
404
+ 0% { background-position: 0% 50%; }
405
+ 50% { background-position: 100% 50%; }
406
+ 100% { background-position: 0% 50%; }
407
+ }
408
+
409
+ /* Responsive design */
410
+ @media (max-width: 768px) {
411
+ .finance-header h1 {
412
+ font-size: 2rem !important;
413
  }
414
+
415
+ .form-section {
416
+ padding: 1.5rem !important;
 
 
 
417
  }
 
 
418
 
419
+ .main-content {
420
+ margin: 1rem !important;
421
+ padding: 1.5rem !important;
422
+ }
423
+ }
 
424
 
425
+ /* Chart and finance icons */
426
+ .finance-bg {
427
+ position: relative;
428
+ overflow: hidden;
429
+ }
430
+
431
+ .finance-bg::after {
432
+ content: "๐Ÿ“ˆ๐Ÿ“Š๐Ÿ’ฐ๐Ÿฆ๐Ÿ’ณ๐Ÿ“‹";
433
+ position: absolute;
434
+ top: -20px;
435
+ right: -20px;
436
+ font-size: 6rem;
437
+ opacity: 0.05;
438
+ z-index: 0;
439
+ transform: rotate(12deg);
440
+ }
441
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
442
 
443
+ # Create the enhanced interface
444
+ with gr.Blocks(
445
+ theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"),
446
+ title="๐Ÿ’ผ AI Investment Strategist Pro",
447
+ css=custom_css
448
+ ) as interface:
449
+
450
+ # Header Section
451
+ with gr.Row(elem_classes="finance-header finance-bg"):
452
+ gr.HTML("""
453
+ <div style="text-align: center; position: relative; z-index: 1;">
454
+ <div class="finance-icon">๐Ÿ’ผ</div>
455
+ <h1>AI Investment Strategist Pro</h1>
456
+ <p>Professional-Grade Investment Strategy Generator</p>
457
+ <div style="margin-top: 1rem; font-size: 0.95rem; opacity: 0.8;">
458
+ ๐Ÿค– Powered by Advanced AI โ€ข ๐Ÿ”’ Secure & Private โ€ข ๐Ÿ“Š Data-Driven Insights
459
+ </div>
460
+ </div>
461
+ """)
462
+
463
+ with gr.Row(elem_classes="main-content"):
464
+ with gr.Column():
465
+
466
+ # Personal Information Section
467
+ with gr.Group(elem_classes="form-section"):
468
+ gr.HTML("<h3>๐Ÿ‘ค Personal Profile</h3>")
469
+
470
+ with gr.Row():
471
+ age_group = gr.Dropdown(
472
+ choices=["20s", "30s", "40s", "50s+"],
473
+ label="๐Ÿ“… Age Group",
474
+ value="30s",
475
+ info="Your current life stage affects investment timeline"
476
+ )
477
+
478
+ country = gr.Dropdown(
479
+ choices=[
480
+ "๐Ÿ‡บ๐Ÿ‡ธ United States", "๐Ÿ‡จ๐Ÿ‡ฆ Canada", "๐Ÿ‡ฌ๐Ÿ‡ง United Kingdom",
481
+ "๐Ÿ‡ฉ๐Ÿ‡ช Germany", "๐Ÿ‡ซ๐Ÿ‡ท France", "๐Ÿ‡ฎ๐Ÿ‡น Italy", "๐Ÿ‡ฏ๐Ÿ‡ต Japan", "๐Ÿ‡ฎ๐Ÿ‡ณ India"
482
+ ],
483
+ label="๐ŸŒ Country of Residence",
484
+ value="๐Ÿ‡บ๐Ÿ‡ธ United States",
485
+ info="Tax jurisdiction for investment recommendations"
486
+ )
487
+
488
+ # Financial Information Section
489
+ with gr.Group(elem_classes="form-section"):
490
+ gr.HTML("<h3>๐Ÿ’ฐ Financial Overview</h3>")
491
+
492
+ with gr.Row():
493
+ income = gr.Number(
494
+ label="๐Ÿ’ต Monthly Income ($)",
495
+ value=6000,
496
+ minimum=0,
497
+ info="Total monthly income before taxes and deductions"
498
+ )
499
+ expenses = gr.Number(
500
+ label="๐Ÿ’ธ Monthly Expenses ($)",
501
+ value=4000,
502
+ minimum=0,
503
+ info="Total monthly living expenses and obligations"
504
+ )
505
+
506
+ # Financial health indicator
507
+ gr.HTML("""
508
+ <div style="background: linear-gradient(90deg, #10b981, #059669); color: white;
509
+ padding: 1rem; border-radius: 8px; margin-top: 1rem; font-size: 0.9rem;">
510
+ ๐Ÿ’ก <strong>Quick Tip:</strong> A healthy savings rate is typically 20% or more of your income
511
+ </div>
512
+ """)
513
+
514
+ # Investment Preferences Section
515
+ with gr.Group(elem_classes="form-section"):
516
+ gr.HTML("<h3>๐ŸŽฏ Investment Strategy</h3>")
517
+
518
  risk_profile = gr.Radio(
519
+ choices=["๐Ÿ›ก๏ธ Conservative", "โš–๏ธ Moderate", "๐Ÿš€ Aggressive"],
520
+ label="๐Ÿ“Š Risk Tolerance",
521
+ value="โš–๏ธ Moderate",
522
+ info="How comfortable are you with potential investment losses?"
 
 
 
 
 
 
523
  )
524
+
525
+ with gr.Row():
526
+ goal = gr.Textbox(
527
+ label="๐ŸŽฏ Primary Financial Goal",
528
+ placeholder="e.g., Down payment for house, retirement planning, children's education, emergency fund",
529
+ info="Be specific about what you're working towards",
530
+ lines=2
531
+ )
532
+ timeframe = gr.Textbox(
533
+ label="โฐ Investment Timeline",
534
+ placeholder="e.g., 3-5 years, 10+ years, until age 65",
535
+ info="When do you need to access these funds?",
536
+ lines=2
537
+ )
538
+
539
+ # Action Buttons
540
+ with gr.Row():
541
+ with gr.Column(scale=3):
542
+ submit_btn = gr.Button(
543
+ "๐Ÿš€ Generate My Investment Strategy",
544
+ variant="primary",
545
+ size="lg",
546
+ elem_classes="primary-btn"
547
+ )
548
+ with gr.Column(scale=1):
549
+ test_btn = gr.Button(
550
+ "๐Ÿ” Test Service",
551
+ variant="secondary",
552
+ size="lg",
553
+ elem_classes="secondary-btn"
554
+ )
555
+
556
+ # Tips Section
557
+ with gr.Group(elem_classes="tips-section"):
558
+ gr.HTML("""
559
+ <h4>๐Ÿ’ก Pro Tips for Better Results</h4>
560
+ <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-top: 1rem;">
561
+ <div style="display: flex; align-items: start; gap: 0.5rem;">
562
+ <span style="color: #10b981; font-size: 1.2rem;">โœ“</span>
563
+ <span><strong>Be Specific:</strong> Detailed goals lead to better recommendations</span>
564
+ </div>
565
+ <div style="display: flex; align-items: start; gap: 0.5rem;">
566
+ <span style="color: #10b981; font-size: 1.2rem;">โœ“</span>
567
+ <span><strong>Realistic Timeline:</strong> Match your goals with appropriate timeframes</span>
568
+ </div>
569
+ <div style="display: flex; align-items: start; gap: 0.5rem;">
570
+ <span style="color: #10b981; font-size: 1.2rem;">โœ“</span>
571
+ <span><strong>Know Your Risk:</strong> Be honest about your comfort level</span>
572
+ </div>
573
+ <div style="display: flex; align-items: start; gap: 0.5rem;">
574
+ <span style="color: #10b981; font-size: 1.2rem;">โœ“</span>
575
+ <span><strong>Positive Cash Flow:</strong> Ensure income exceeds expenses</span>
576
+ </div>
577
+ </div>
578
+ """)
579
+
580
+ # Output Section
581
+ with gr.Group(elem_classes="output-area"):
582
+ output = gr.Markdown(
583
+ value="""
584
+ ## ๐ŸŽฏ Ready to Get Started?
585
+
586
+ Fill out your financial profile above and click **"Generate My Investment Strategy"** to receive:
587
+
588
+ ๐Ÿ“‹ **Personalized Investment Plan**
589
+ ๐Ÿ“Š **Asset Allocation Recommendations**
590
+ ๐Ÿฆ **Account Type Suggestions**
591
+ ๐Ÿ’ก **Tax Optimization Strategies**
592
+ ๐Ÿ“ˆ **Risk Management Advice**
593
+
594
+ *Your data is processed securely and never stored permanently.*
595
+ """,
596
+ elem_id="strategy-output"
597
  )
598
 
599
+ # Event handlers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
600
  submit_btn.click(
601
  fn=get_investment_strategy,
602
  inputs=[age_group, income, expenses, risk_profile, goal, timeframe, country],
 
617
  share=False,
618
  show_error=True,
619
  debug=True
620
+ )