cryman38 commited on
Commit
a0138b8
Β·
verified Β·
1 Parent(s): dbbd0b8

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -121
app.py CHANGED
@@ -379,7 +379,7 @@ def gradio_cost_averaging(old_avg_price, old_quantity, new_price, new_quantity):
379
  </div>
380
  </div>
381
  </div>
382
- <div>➜</div>
383
  <div style='text-align: center;'>
384
  <div style="margin-bottom: 24px;">
385
  <div style="font-size: 24px; margin-bottom: 24px;"></div>
@@ -399,129 +399,86 @@ def gradio_cost_averaging(old_avg_price, old_quantity, new_price, new_quantity):
399
  return result_html
400
 
401
 
402
- pf_dataset_samples = [
403
- ["458730 krw 571 8,\n368590 krw 80 2", 17172, 0],
404
- ["SCHD USD 400 8,\nQQQ USD 40 2", 1000000, 25],
405
- ["458730 krw 571 8,\n368590 krw 80 2,\nSCHD USD 400 8,\nQQQ USD 40 2", 1000000, 25]
 
 
 
 
 
 
 
 
406
  ]
407
- stock_dataset_samples = [
408
- ["SCHD,QQQ", 30],
409
- ["458730,368590", 30],
410
- ["AAPL,GOOGL,MSFT", 30]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  ]
412
- average_dataset_samples = [
413
- [78.15, 6.024272, 77.11, 1]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  ]
 
 
 
 
 
 
 
 
 
 
 
 
415
  with gr.Blocks(css='style.css') as demo:
416
  with gr.Column(elem_id="col-container"):
417
-
418
  with gr.Tabs():
419
  with gr.TabItem("Portfolio"):
420
- with gr.Column():
421
- input_text = gr.Textbox(label="πŸ”₯ Holdings", lines=2, placeholder="Format: [stock code currency quantity target weight, ...]")
422
- with gr.Row():
423
- cash_amount = gr.Number(label="πŸͺ΅ Cash", value="")
424
- cash_ratio = gr.Slider(label="βš–οΈ Cash Ratio (%)", minimum=0, maximum=100, step=1)
425
- pf_dataset = Dataset(components=[input_text], samples=pf_dataset_samples, label=None)
426
- pf_dataset.click(fn=lambda x: x, inputs=pf_dataset, outputs=[input_text, cash_amount, cash_ratio])
427
- rebalance_button = gr.Button("Analyze Data")
428
- gr.Markdown("---")
429
- pf_result = gr.HTML()
430
- # input_text.change(
431
- # rebalancing_tool,
432
- # inputs=[input_text, cash_amount, cash_ratio],
433
- # outputs=pf_result
434
- # )
435
- # cash_amount.change(
436
- # rebalancing_tool,
437
- # inputs=[input_text, cash_amount, cash_ratio],
438
- # outputs=pf_result
439
- # )
440
- # cash_ratio.change(
441
- # rebalancing_tool,
442
- # inputs=[input_text, cash_amount, cash_ratio],
443
- # outputs=pf_result
444
- # )
445
- rebalance_button.click(rebalancing_tool, [input_text, cash_amount, cash_ratio], pf_result)
446
- clear_button = gr.ClearButton([input_text, cash_amount, cash_ratio, pf_result], value="Clear")
447
-
448
-
449
  with gr.TabItem("Compare"):
450
- with gr.Row():
451
- stock_codes = gr.Textbox(label="πŸ“ˆ Stock Codes", lines=2, placeholder="Enter stock codes separated by comma (e.g., AAPL,GOOGL,MSFT)")
452
- period = gr.Textbox(label="πŸ“† Period (days)", placeholder="e.g. 30")
453
- stock_dataset = Dataset(components=[stock_codes], samples=stock_dataset_samples, label=None)
454
- stock_dataset.click(
455
- fn=lambda x: x,
456
- inputs=stock_dataset, # λ°μ΄ν„°μ„ΈνŠΈ 자체λ₯Ό μž…λ ₯으둜 지정
457
- outputs=[stock_codes, period] # κ²°κ³Ό λ©”μ‹œμ§€ 및 μž…λ ₯ ν•„λ“œλ“€μ„ 좜λ ₯으둜 μ„€μ •
458
- )
459
- compare_button = gr.Button("Compare Stock Prices")
460
- gr.Markdown("---")
461
- comparison_result = gr.HTML()
462
- # stock_codes.change(
463
- # plot_stock_prices,
464
- # inputs=[stock_codes, period],
465
- # outputs=comparison_result
466
- # )
467
- # period.change(
468
- # plot_stock_prices,
469
- # inputs=[stock_codes, period],
470
- # outputs=comparison_result
471
- # )
472
- compare_button.click(plot_stock_prices, [stock_codes, period], comparison_result)
473
- clear_button = gr.ClearButton([stock_codes, period, comparison_result], value="Clear")
474
-
475
  with gr.TabItem("Cost Averaging"):
476
- with gr.Accordion("πŸ“‰ First Purchase", open=True):
477
- old_avg_price_input = gr.Number(label="Old Price", value="")
478
- old_quantity_input = gr.Number(label="Quantity", value="")
479
- with gr.Accordion("πŸ’§ Second Purchase", open=True):
480
- new_price_input = gr.Number(label="New Price", value="")
481
- new_quantity_input = gr.Number(label="Quantity", value="")
482
-
483
- average_button = gr.Button("Calculate Cost Averaging")
484
- gr.Markdown("---")
485
- average_results = gr.HTML() # Changed to HTML for styled output
486
-
487
- inputs = [old_avg_price_input, old_quantity_input, new_price_input, new_quantity_input]
488
-
489
- # old_avg_price_input.change(
490
- # gradio_cost_averaging,
491
- # inputs=inputs,
492
- # outputs=average_results
493
- # )
494
- # old_quantity_input.change(
495
- # gradio_cost_averaging,
496
- # inputs=inputs,
497
- # outputs=average_results
498
- # )
499
- # new_price_input.change(
500
- # gradio_cost_averaging,
501
- # inputs=inputs,
502
- # outputs=average_results
503
- # )
504
- # new_quantity_input.change(
505
- # gradio_cost_averaging,
506
- # inputs=inputs,
507
- # outputs=average_results
508
- # )
509
-
510
- average_dataset = Dataset(components=[old_avg_price_input], samples=average_dataset_samples, label=None)
511
- average_dataset.click(
512
- fn=lambda x: x,
513
- inputs=average_dataset, # λ°μ΄ν„°μ„ΈνŠΈ 자체λ₯Ό μž…λ ₯으둜 지정
514
- outputs=[old_avg_price_input, old_quantity_input, new_price_input, new_quantity_input] # κ²°κ³Ό λ©”μ‹œμ§€ 및 μž…λ ₯ ν•„λ“œλ“€μ„ 좜λ ₯으둜 μ„€μ •
515
- )
516
-
517
- average_button.click(
518
- gradio_cost_averaging,
519
- inputs=inputs,
520
- outputs=average_results
521
- )
522
-
523
- clear_button = gr.ClearButton([old_avg_price_input, old_quantity_input, new_price_input, new_quantity_input, average_results], value="Clear")
524
-
525
  with gr.TabItem("πŸ“„ About"):
526
  gr.Markdown("""
527
  # About This Application
@@ -578,11 +535,6 @@ with gr.Blocks(css='style.css') as demo:
578
  We hope you find this tool useful for managing your investments. If you have any feedback or suggestions, feel free to reach out!
579
 
580
  Happy Investing!
581
-
582
-
583
  """)
584
-
585
-
586
 
587
- demo.launch(share=True)
588
-
 
379
  </div>
380
  </div>
381
  </div>
382
+ <div style='text-align: center; margin-bottom: 24px; font-size: 24px;'>➜</div>
383
  <div style='text-align: center;'>
384
  <div style="margin-bottom: 24px;">
385
  <div style="font-size: 24px; margin-bottom: 24px;"></div>
 
399
  return result_html
400
 
401
 
402
+
403
+
404
+
405
+ # Define the interface for the Portfolio tab
406
+ def portfolio_interface(input_text, cash_amount, cash_ratio):
407
+ result = rebalancing_tool(input_text, cash_amount, cash_ratio)
408
+ return result
409
+
410
+ portfolio_inputs = [
411
+ gr.Textbox(label="πŸ”₯ Holdings", lines=2, placeholder="Format: [stock code currency quantity target weight, ...]"),
412
+ gr.Number(label="πŸͺ΅ Cash", value=""),
413
+ gr.Slider(label="βš–οΈ Cash Ratio (%)", minimum=0, maximum=100, step=1)
414
  ]
415
+
416
+ portfolio_interface = gr.Interface(
417
+ fn=portfolio_interface,
418
+ inputs=portfolio_inputs,
419
+ outputs=gr.HTML(),
420
+ # examples = [
421
+ # ["458730 krw 571 8,\n368590 krw 80 2", 17172, 0],
422
+ # ["SCHD USD 400 8,\nQQQ USD 40 2", 1000000, 25],
423
+ # ["458730 krw 571 8,\n368590 krw 80 2,\nSCHD USD 400 8,\nQQQ USD 40 2", 1000000, 25]
424
+ # ],
425
+ live=True
426
+ )
427
+
428
+ # Define the interface for the Compare tab
429
+ def compare_interface(stock_codes, period):
430
+ result = plot_stock_prices(stock_codes, period)
431
+ return result
432
+
433
+ compare_inputs = [
434
+ gr.Textbox(label="πŸ“ˆ Stock Codes", lines=2, placeholder="Enter stock codes separated by comma (e.g., AAPL,GOOGL,MSFT)"),
435
+ gr.Number(label="πŸ“† Period (days)", value=90)
436
  ]
437
+
438
+ compare_interface = gr.Interface(
439
+ fn=compare_interface,
440
+ inputs=compare_inputs,
441
+ outputs=gr.HTML(),
442
+ # examples = [
443
+ # ["SCHD,QQQ", 90],
444
+ # ["458730,368590", 90],
445
+ # ["AAPL,GOOGL,MSFT", 90]
446
+ # ],
447
+ live=False
448
+ )
449
+
450
+ # Define the interface for the Cost Averaging tab
451
+ def cost_averaging_interface(old_avg_price, old_quantity, new_price, new_quantity):
452
+ result = gradio_cost_averaging(old_avg_price, old_quantity, new_price, new_quantity)
453
+ return result
454
+
455
+ cost_averaging_inputs = [
456
+ gr.Number(label="Old Price", value=""),
457
+ gr.Number(label="Quantity", value=""),
458
+ gr.Number(label="New Price", value=""),
459
+ gr.Number(label="Quantity", value="")
460
  ]
461
+
462
+ cost_averaging_interface = gr.Interface(
463
+ fn=cost_averaging_interface,
464
+ inputs=cost_averaging_inputs,
465
+ outputs=gr.HTML(),
466
+ # examples = [
467
+ # [78.15, 6.024272, 77.11, 1]
468
+ # ],
469
+ live=True
470
+ )
471
+
472
+ # Combine all interfaces into a tabbed interface
473
  with gr.Blocks(css='style.css') as demo:
474
  with gr.Column(elem_id="col-container"):
 
475
  with gr.Tabs():
476
  with gr.TabItem("Portfolio"):
477
+ portfolio_interface.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  with gr.TabItem("Compare"):
479
+ compare_interface.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
  with gr.TabItem("Cost Averaging"):
481
+ cost_averaging_interface.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
  with gr.TabItem("πŸ“„ About"):
483
  gr.Markdown("""
484
  # About This Application
 
535
  We hope you find this tool useful for managing your investments. If you have any feedback or suggestions, feel free to reach out!
536
 
537
  Happy Investing!
 
 
538
  """)
 
 
539
 
540
+ demo.launch(share=True)