Devavrat28 commited on
Commit
cd9103f
Β·
verified Β·
1 Parent(s): ad511ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -292
app.py CHANGED
@@ -5,6 +5,7 @@ import json
5
  import asyncio
6
  import aiohttp
7
  from typing import Optional
 
8
 
9
  # Update this to your new optimized Modal URL
10
  MODAL_URL = "https://devsam2898--personal-investment-strategist-optimized-web.modal.run/strategy"
@@ -199,259 +200,25 @@ def test_service():
199
  return result
200
  except Exception as e:
201
  return f"❌ **Test Error**: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
  # Fixed CSS - Removed problematic dropdown overrides
204
- # custom_css = """
205
- # /* Global container styling */
206
- # .gradio-container {
207
- # max-width: 1400px !important;
208
- # margin: 0 auto !important;
209
- # background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
210
- # min-height: 100vh;
211
- # font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
212
- # }
213
-
214
- # /* Main content area */
215
- # .main-content {
216
- # background: rgba(255, 255, 255, 0.95) !important;
217
- # backdrop-filter: blur(20px) !important;
218
- # border-radius: 20px !important;
219
- # padding: 2rem !important;
220
- # margin: 2rem !important;
221
- # box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1) !important;
222
- # border: 1px solid rgba(255, 255, 255, 0.2) !important;
223
- # }
224
-
225
- # /* Header styling */
226
- # .finance-header {
227
- # text-align: center;
228
- # background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
229
- # color: white;
230
- # padding: 3rem 2rem;
231
- # border-radius: 20px;
232
- # margin-bottom: 2rem;
233
- # position: relative;
234
- # overflow: hidden;
235
- # }
236
-
237
- # .finance-header::before {
238
- # content: "";
239
- # position: absolute;
240
- # top: 0;
241
- # left: 0;
242
- # right: 0;
243
- # bottom: 0;
244
- # 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>');
245
- # opacity: 0.1;
246
- # }
247
-
248
- # .finance-header h1 {
249
- # font-size: 3rem !important;
250
- # font-weight: 800 !important;
251
- # margin-bottom: 1rem !important;
252
- # background: linear-gradient(45deg, #ffffff, #e0e7ff);
253
- # -webkit-background-clip: text;
254
- # -webkit-text-fill-color: transparent;
255
- # position: relative;
256
- # z-index: 1;
257
- # }
258
-
259
- # .finance-header p {
260
- # font-size: 1.25rem !important;
261
- # opacity: 0.9 !important;
262
- # margin-bottom: 0 !important;
263
- # position: relative;
264
- # z-index: 1;
265
- # }
266
-
267
- # /* Icon styling */
268
- # .finance-icon {
269
- # font-size: 4rem;
270
- # margin-bottom: 1rem;
271
- # position: relative;
272
- # z-index: 1;
273
- # }
274
-
275
- # /* Form sections */
276
- # .form-section {
277
- # background: white !important;
278
- # border-radius: 16px !important;
279
- # padding: 2rem !important;
280
- # margin-bottom: 1.5rem !important;
281
- # box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08) !important;
282
- # border: 1px solid rgba(255, 255, 255, 0.2) !important;
283
- # transition: all 0.3s ease !important;
284
- # }
285
-
286
- # .form-section:hover {
287
- # box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12) !important;
288
- # transform: translateY(-2px) !important;
289
- # }
290
-
291
- # .form-section h3 {
292
- # color: #1e3c72 !important;
293
- # font-weight: 700 !important;
294
- # font-size: 1.5rem !important;
295
- # margin-bottom: 1.5rem !important;
296
- # display: flex !important;
297
- # align-items: center !important;
298
- # gap: 0.75rem !important;
299
- # }
300
-
301
- # /* Input styling - only for textboxes and numbers, NOT dropdowns */
302
- # input[type="text"], input[type="number"], textarea {
303
- # border-radius: 12px !important;
304
- # border: 2px solid #e5e7eb !important;
305
- # transition: all 0.3s ease !important;
306
- # font-size: 1rem !important;
307
- # padding: 0.75rem 1rem !important;
308
- # }
309
-
310
- # input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
311
- # border-color: #667eea !important;
312
- # box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
313
- # outline: none !important;
314
- # }
315
-
316
- # /* Minimal dropdown styling - let Gradio handle the functionality */
317
- # .gradio-dropdown {
318
- # margin-bottom: 1rem !important;
319
- # }
320
-
321
- # /* Button styling */
322
- # .primary-btn {
323
- # background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
324
- # border: none !important;
325
- # border-radius: 12px !important;
326
- # padding: 1rem 2rem !important;
327
- # font-size: 1.1rem !important;
328
- # font-weight: 600 !important;
329
- # color: white !important;
330
- # transition: all 0.3s ease !important;
331
- # box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3) !important;
332
- # min-height: 56px !important;
333
- # }
334
-
335
- # .primary-btn:hover {
336
- # transform: translateY(-2px) !important;
337
- # box-shadow: 0 12px 32px rgba(102, 126, 234, 0.4) !important;
338
- # }
339
-
340
- # .secondary-btn {
341
- # background: linear-gradient(135deg, #64748b 0%, #475569 100%) !important;
342
- # border: none !important;
343
- # border-radius: 12px !important;
344
- # padding: 1rem 2rem !important;
345
- # font-size: 1.1rem !important;
346
- # font-weight: 600 !important;
347
- # color: white !important;
348
- # transition: all 0.3s ease !important;
349
- # box-shadow: 0 8px 24px rgba(100, 116, 139, 0.3) !important;
350
- # min-height: 56px !important;
351
- # }
352
-
353
- # .secondary-btn:hover {
354
- # transform: translateY(-2px) !important;
355
- # box-shadow: 0 12px 32px rgba(100, 116, 139, 0.4) !important;
356
- # }
357
-
358
- # /* Output area styling */
359
- # .output-area {
360
- # background: white !important;
361
- # border-radius: 16px !important;
362
- # padding: 2rem !important;
363
- # margin-top: 2rem !important;
364
- # box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08) !important;
365
- # border: 1px solid rgba(255, 255, 255, 0.2) !important;
366
- # min-height: 200px !important;
367
- # }
368
-
369
- # /* Tips section */
370
- # .tips-section {
371
- # background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%) !important;
372
- # border-radius: 16px !important;
373
- # padding: 2rem !important;
374
- # margin: 2rem 0 !important;
375
- # border-left: 4px solid #667eea !important;
376
- # }
377
-
378
- # .tips-section h4 {
379
- # color: #1e3c72 !important;
380
- # font-weight: 700 !important;
381
- # margin-bottom: 1rem !important;
382
- # }
383
-
384
- # /* Radio button styling */
385
- # .gradio-radio {
386
- # gap: 1rem !important;
387
- # }
388
-
389
- # .gradio-radio label {
390
- # background: white !important;
391
- # border: 2px solid #e5e7eb !important;
392
- # border-radius: 12px !important;
393
- # padding: 1rem !important;
394
- # transition: all 0.3s ease !important;
395
- # cursor: pointer !important;
396
- # }
397
-
398
- # .gradio-radio label:hover {
399
- # border-color: #667eea !important;
400
- # background: #f8fafc !important;
401
- # }
402
-
403
- # .gradio-radio input:checked + label {
404
- # border-color: #667eea !important;
405
- # background: linear-gradient(135deg, #667eea10, #764ba210) !important;
406
- # color: #1e3c72 !important;
407
- # }
408
-
409
- # /* Progress indicator */
410
- # .loading-indicator {
411
- # background: linear-gradient(90deg, #667eea, #764ba2, #667eea) !important;
412
- # background-size: 200% 100% !important;
413
- # animation: gradient 2s ease infinite !important;
414
- # }
415
-
416
- # @keyframes gradient {
417
- # 0% { background-position: 0% 50%; }
418
- # 50% { background-position: 100% 50%; }
419
- # 100% { background-position: 0% 50%; }
420
- # }
421
-
422
- # /* Responsive design */
423
- # @media (max-width: 768px) {
424
- # .finance-header h1 {
425
- # font-size: 2rem !important;
426
- # }
427
-
428
- # .form-section {
429
- # padding: 1.5rem !important;
430
- # }
431
-
432
- # .main-content {
433
- # margin: 1rem !important;
434
- # padding: 1.5rem !important;
435
- # }
436
- # }
437
-
438
- # /* Chart and finance icons */
439
- # .finance-bg {
440
- # position: relative;
441
- # overflow: hidden;
442
- # }
443
-
444
- # .finance-bg::after {
445
- # content: "πŸ“ˆπŸ“ŠπŸ’°πŸ¦πŸ’³πŸ“‹";
446
- # position: absolute;
447
- # top: -20px;
448
- # right: -20px;
449
- # font-size: 6rem;
450
- # opacity: 0.05;
451
- # z-index: 0;
452
- # transform: rotate(12deg);
453
- # }
454
- # """
455
  custom_css = """
456
  /* Global container styling */
457
  .gradio-container {
@@ -540,7 +307,7 @@ custom_css = """
540
  }
541
 
542
  .form-section h3 {
543
- color: #1e3c72 !important;
544
  font-weight: 700 !important;
545
  font-size: 1.5rem !important;
546
  margin-bottom: 1.5rem !important;
@@ -564,24 +331,11 @@ input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
564
  outline: none !important;
565
  }
566
 
567
- /* Corrected dropdown styling for visibility and clickability */
568
- /* Ensure dropdown options appear on top and are clickable */
569
  .gradio-dropdown {
570
  margin-bottom: 1rem !important;
571
- /* Add z-index to ensure dropdown options appear above other content */
572
- z-index: 1000 !important;
573
- position: relative !important; /* Ensure z-index takes effect */
574
- }
575
-
576
- /* Target the dropdown options list specifically if needed (common Gradio class for overlay) */
577
- .gr-box.gr-options { /* This might be the actual class for the dropdown menu */
578
- z-index: 1001 !important; /* Higher than the dropdown container itself */
579
- position: relative !important;
580
- /* You might also need to ensure no parent has overflow: hidden that clips it */
581
- overflow: visible !important;
582
  }
583
 
584
-
585
  /* Button styling */
586
  .primary-btn {
587
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
@@ -616,7 +370,7 @@ input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
616
 
617
  .secondary-btn:hover {
618
  transform: translateY(-2px) !important;
619
- box_shadow: 0 12px 32px rgba(100, 116, 139, 0.4) !important;
620
  }
621
 
622
  /* Output area styling */
@@ -640,7 +394,7 @@ input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
640
  }
641
 
642
  .tips-section h4 {
643
- color: #1e3c72 !important;
644
  font-weight: 700 !important;
645
  margin-bottom: 1rem !important;
646
  }
@@ -688,11 +442,11 @@ input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
688
  .finance-header h1 {
689
  font-size: 2rem !important;
690
  }
691
-
692
  .form-section {
693
  padding: 1.5rem !important;
694
  }
695
-
696
  .main-content {
697
  margin: 1rem !important;
698
  padding: 1.5rem !important;
@@ -717,11 +471,10 @@ input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
717
  }
718
  """
719
 
720
-
721
  # Create the enhanced interface
722
  with gr.Blocks(
723
  theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"),
724
- title="πŸ’Ό AI Investment Strategist Pro",
725
  css=custom_css
726
  ) as interface:
727
 
@@ -730,7 +483,7 @@ with gr.Blocks(
730
  gr.HTML("""
731
  <div style="text-align: center; position: relative; z-index: 1;">
732
  <div class="finance-icon">πŸ’Ό</div>
733
- <h1>AI Investment Strategist Pro</h1>
734
  <p>Professional-Grade Investment Strategy Generator</p>
735
  <div style="margin-top: 1rem; font-size: 0.95rem; opacity: 0.8;">
736
  πŸ€– Powered by Advanced AI β€’ πŸ”’ Secure & Private β€’ πŸ“Š Data-Driven Insights
@@ -744,28 +497,24 @@ with gr.Blocks(
744
  # Personal Information Section
745
  with gr.Group(elem_classes="form-section"):
746
  gr.HTML("<h3>πŸ‘€ Personal Profile</h3>")
747
-
748
  with gr.Row():
749
- age_group = gr.Dropdown(
750
- choices=["20s", "30s", "40s", "50s+"],
751
  label="πŸ“… Age Group",
752
  value="30s",
753
  info="Your current life stage affects investment timeline",
754
  interactive=True,
755
  show_label=True
756
  )
757
-
758
- country = gr.Dropdown(
759
- choices=[
760
- "United States", "Canada", "United Kingdom",
761
- "Germany", "France", "Italy", "Japan", "India"
762
- ],
763
  label="🌍 Country of Residence",
764
  value="United States",
765
  info="Tax jurisdiction for investment recommendations",
766
  interactive=True,
767
  show_label=True
768
  )
 
769
 
770
  # Financial Information Section
771
  with gr.Group(elem_classes="form-section"):
@@ -874,24 +623,44 @@ with gr.Blocks(
874
  """)
875
 
876
  # Output Section
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
877
  with gr.Group(elem_classes="output-area"):
878
  output = gr.Markdown(
879
  value="""
880
  ## 🎯 Ready to Get Started?
881
-
882
- Fill out your financial profile above and click **"Generate My Investment Strategy"** to receive:
883
-
884
- πŸ“‹ **Personalized Investment Plan**
885
- πŸ“Š **Asset Allocation Recommendations**
886
- 🏦 **Account Type Suggestions**
887
- πŸ’‘ **Tax Optimization Strategies**
888
- πŸ“ˆ **Risk Management Advice**
889
- πŸ’³ **Debt Management Guidance**
890
-
891
  *Your data is processed securely and never stored permanently.*
892
  """,
893
  elem_id="strategy-output"
894
  )
 
 
895
 
896
  # Event handlers
897
  submit_btn.click(
@@ -907,6 +676,12 @@ with gr.Blocks(
907
  show_progress=True
908
  )
909
 
 
 
 
 
 
 
910
  if __name__ == "__main__":
911
  interface.launch(
912
  server_name="0.0.0.0",
 
5
  import asyncio
6
  import aiohttp
7
  from typing import Optional
8
+ from fpdf import FPDF
9
 
10
  # Update this to your new optimized Modal URL
11
  MODAL_URL = "https://devsam2898--personal-investment-strategist-optimized-web.modal.run/strategy"
 
200
  return result
201
  except Exception as e:
202
  return f"❌ **Test Error**: {str(e)}"
203
+
204
+ def generate_pdf(strategy):
205
+ pdf = FPDF()
206
+ pdf.add_page()
207
+ pdf.set_font("Arial", size=12)
208
+
209
+ # Add strategy content to PDF
210
+ for line in strategy.split('\n'):
211
+ pdf.cell(0, 10, txt=line, ln=True)
212
+
213
+ pdf_output = "investment_strategy.pdf"
214
+ pdf.output(pdf_output)
215
+ return pdf_output
216
+
217
+ def download_strategy(strategy):
218
+ pdf_path = generate_pdf(strategy)
219
+ return pdf_path
220
 
221
  # Fixed CSS - Removed problematic dropdown overrides
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  custom_css = """
223
  /* Global container styling */
224
  .gradio-container {
 
307
  }
308
 
309
  .form-section h3 {
310
+ color: #ffffff !important;
311
  font-weight: 700 !important;
312
  font-size: 1.5rem !important;
313
  margin-bottom: 1.5rem !important;
 
331
  outline: none !important;
332
  }
333
 
334
+ /* Minimal dropdown styling - let Gradio handle the functionality */
 
335
  .gradio-dropdown {
336
  margin-bottom: 1rem !important;
 
 
 
 
 
 
 
 
 
 
 
337
  }
338
 
 
339
  /* Button styling */
340
  .primary-btn {
341
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
 
370
 
371
  .secondary-btn:hover {
372
  transform: translateY(-2px) !important;
373
+ box-shadow: 0 12px 32px rgba(100, 116, 139, 0.4) !important;
374
  }
375
 
376
  /* Output area styling */
 
394
  }
395
 
396
  .tips-section h4 {
397
+ color: #ffffff !important;
398
  font-weight: 700 !important;
399
  margin-bottom: 1rem !important;
400
  }
 
442
  .finance-header h1 {
443
  font-size: 2rem !important;
444
  }
445
+
446
  .form-section {
447
  padding: 1.5rem !important;
448
  }
449
+
450
  .main-content {
451
  margin: 1rem !important;
452
  padding: 1.5rem !important;
 
471
  }
472
  """
473
 
 
474
  # Create the enhanced interface
475
  with gr.Blocks(
476
  theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"),
477
+ title="πŸ’Ό Vittaśāstra - AI Strategist",
478
  css=custom_css
479
  ) as interface:
480
 
 
483
  gr.HTML("""
484
  <div style="text-align: center; position: relative; z-index: 1;">
485
  <div class="finance-icon">πŸ’Ό</div>
486
+ <h1>Vittaśāstra - AI Strategist</h1>
487
  <p>Professional-Grade Investment Strategy Generator</p>
488
  <div style="margin-top: 1rem; font-size: 0.95rem; opacity: 0.8;">
489
  πŸ€– Powered by Advanced AI β€’ πŸ”’ Secure & Private β€’ πŸ“Š Data-Driven Insights
 
497
  # Personal Information Section
498
  with gr.Group(elem_classes="form-section"):
499
  gr.HTML("<h3>πŸ‘€ Personal Profile</h3>")
500
+
501
  with gr.Row():
502
+ age_group = gr.Textbox(
 
503
  label="πŸ“… Age Group",
504
  value="30s",
505
  info="Your current life stage affects investment timeline",
506
  interactive=True,
507
  show_label=True
508
  )
509
+
510
+ country = gr.Textbox(
 
 
 
 
511
  label="🌍 Country of Residence",
512
  value="United States",
513
  info="Tax jurisdiction for investment recommendations",
514
  interactive=True,
515
  show_label=True
516
  )
517
+
518
 
519
  # Financial Information Section
520
  with gr.Group(elem_classes="form-section"):
 
623
  """)
624
 
625
  # Output Section
626
+ # with gr.Group(elem_classes="output-area"):
627
+ # output = gr.Markdown(
628
+ # value="""
629
+ # ## 🎯 Ready to Get Started?
630
+
631
+ # Fill out your each and every financial profile above and click **"Generate My Investment Strategy"** to receive:
632
+
633
+ # πŸ“‹ **Personalized Investment Plan**
634
+ # πŸ“Š **Asset Allocation Recommendations**
635
+ # 🏦 **Account Type Suggestions**
636
+ # πŸ’‘ **Tax Optimization Strategies**
637
+ # πŸ“ˆ **Risk Management Advice**
638
+ # πŸ’³ **Debt Management Guidance**
639
+
640
+ # *Your data is processed securely and never stored permanently.*
641
+ # """,
642
+ # elem_id="strategy-output"
643
+ # )
644
  with gr.Group(elem_classes="output-area"):
645
  output = gr.Markdown(
646
  value="""
647
  ## 🎯 Ready to Get Started?
648
+
649
+ Fill out your each and every financial profile above and click **"Generate My Investment Strategy"** to receive:
650
+
651
+ πŸ“‹ **Personalized Investment Plan**
652
+ πŸ“Š **Asset Allocation Recommendations**
653
+ 🏦 **Account Type Suggestions**
654
+ πŸ’‘ **Tax Optimization Strategies**
655
+ πŸ“ˆ **Risk Management Advice**
656
+ πŸ’³ **Debt Management Guidance**
657
+
658
  *Your data is processed securely and never stored permanently.*
659
  """,
660
  elem_id="strategy-output"
661
  )
662
+ download_btn = gr.Button("πŸ“₯ Download Strategy as PDF", variant="secondary", elem_classes="secondary-btn")
663
+
664
 
665
  # Event handlers
666
  submit_btn.click(
 
676
  show_progress=True
677
  )
678
 
679
+ download_btn.click(
680
+ fn=download_strategy,
681
+ inputs=output,
682
+ outputs=gr.File(label="Download PDF")
683
+ )
684
+
685
  if __name__ == "__main__":
686
  interface.launch(
687
  server_name="0.0.0.0",