Spaces:
Paused

ll7098ll commited on
Commit
bc852c6
Β·
verified Β·
1 Parent(s): 4ac5d2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -96
app.py CHANGED
@@ -19,90 +19,7 @@ st.set_page_config(
19
  st.markdown(
20
  """
21
  <style>
22
- /* 전체 폰트 λ³€κ²½ (μ˜ˆμ‹œ: Nanum Gothic) */
23
- @import url('https://fonts.googleapis.com/css2?family=Nanum+Gothic:wght@400;700&display=swap');
24
- body {
25
- font-family: 'Nanum Gothic', sans-serif !important;
26
- }
27
-
28
- /* λ²„νŠΌ μŠ€νƒ€μΌ λ³€κ²½ */
29
- div.stButton > button {
30
- background-color: #007bff; /* Blue */
31
- color: white;
32
- padding: 12px 28px;
33
- text-align: center;
34
- text-decoration: none;
35
- display: inline-block;
36
- font-size: 16px;
37
- margin: 6px 3px;
38
- cursor: pointer;
39
- border-radius: 8px; /* Slightly less rounded */
40
- border: none;
41
- }
42
- div.stButton > button:hover {
43
- background-color: #0056b3; /* Darker Blue */
44
- }
45
-
46
- /* λ²„νŠΌ μŠ€νƒ€μΌ (보쑰) */
47
- div.stButton > button.secondary-button {
48
- background-color: #6c757d; /* Gray */
49
- }
50
- div.stButton > button.secondary-button:hover {
51
- background-color: #5a6268; /* Darker Gray */
52
- }
53
-
54
- /* Expander μŠ€νƒ€μΌ */
55
- .streamlit-expanderHeader {
56
- font-weight: bold;
57
- color: #212529; /* Dark Gray */
58
- border-bottom: 1px solid #e0e0e0; /* Lighter Border */
59
- padding-bottom: 8px;
60
- margin-bottom: 15px;
61
- }
62
-
63
- /* Dataframe μŠ€νƒ€μΌ */
64
- .dataframe {
65
- border: 1px solid #e0e0e0; /* Lighter Border */
66
- border-radius: 8px; /* Rounded Corners */
67
- padding: 12px;
68
- }
69
-
70
- /* Info Box μŠ€νƒ€μΌ */
71
- div.stInfo {
72
- background-color: #f0f8ff; /* Light Blue Background */
73
- border-left: 5px solid #007bff; /* Blue Accent */
74
- padding: 15px;
75
- margin-bottom: 15px;
76
- border-radius: 8px; /* Rounded Corners */
77
- }
78
-
79
- /* Success Box μŠ€νƒ€μΌ */
80
- div.stSuccess {
81
- background-color: #e6f7e8; /* Light Green Background */
82
- border-left: 5px solid #28a745; /* Green Accent */
83
- padding: 15px;
84
- margin-bottom: 15px;
85
- border-radius: 8px; /* Rounded Corners */
86
- }
87
-
88
- /* Error Box μŠ€νƒ€μΌ */
89
- div.stError {
90
- background-color: #fcecec; /* Light Red Background */
91
- border-left: 5px solid #dc3545; /* Red Accent */
92
- padding: 15px;
93
- margin-bottom: 15px;
94
- border-radius: 8px; /* Rounded Corners */
95
- }
96
-
97
- /* Warning Box μŠ€νƒ€μΌ */
98
- div.stWarning {
99
- background-color: #fff8e1; /* Light Yellow Background */
100
- border-left: 5px solid #ffc107; /* Yellow Accent */
101
- padding: 15px;
102
- margin-bottom: 15px;
103
- border-radius: 8px; /* Rounded Corners */
104
- }
105
-
106
  </style>
107
  """,
108
  unsafe_allow_html=True,
@@ -227,9 +144,10 @@ if 'day_count' not in st.session_state:
227
  if 'sector_news_impact' not in st.session_state:
228
  st.session_state['sector_news_impact'] = {} # 섹터별 λ‰΄μŠ€ 영ν–₯ μ €μž₯
229
 
 
230
  # --- λ‰΄μŠ€ 생성 ν•¨μˆ˜ ---
231
  def generate_news():
232
- day_count = st.session_state['day_count'] # day_count κ°€μ Έμ˜€κΈ°
233
  prompt = f"""
234
  **μ§€μ‹œ:**
235
  μ΄ˆλ“±ν•™μƒ 6ν•™λ…„ μˆ˜μ€€μ— λ§žμΆ°μ„œ, 주식 μ‹œμž₯κ³Ό κ²½μ œμ— κ΄€λ ¨λœ λ‰΄μŠ€ 기사 **5개**λ₯Ό μƒμ„±ν•΄μ£Όμ„Έμš”.
@@ -335,7 +253,7 @@ def sell_stock(stock_name, quantity):
335
 
336
  sell_price = stock_price * quantity
337
  st.session_state['portfolio']['cash'] += sell_price
338
- st.session_state']['portfolio']['stocks'][stock_name]['quantity'] -= quantity
339
  if st.session_state['portfolio']['stocks'][stock_name]['quantity'] == 0:
340
  del st.session_state['portfolio']['stocks'][stock_name]
341
  st.session_state['messages'].append({"type": "success", "text": f"{stock_name} {quantity}μ£Ό 맀도 μ™„λ£Œ. 총 {sell_price:,.0f}원 νšλ“."})
@@ -487,13 +405,14 @@ def main():
487
  if st.session_state['previous_daily_news'] and st.session_state['news_meanings']:
488
  st.subheader(f"Day {st.session_state['day_count'] - 1} λ‰΄μŠ€ ν•΄μ„€") # Day X-1 λ‰΄μŠ€ ν•΄μ„€
489
  st.info("AIκ°€ λΆ„μ„ν•œ μ–΄μ œ λ‰΄μŠ€ ν•΄μ„€μž…λ‹ˆλ‹€.")
490
- with st.expander(f"Day {st.session_state['day_count'] - 1} λ‰΄μŠ€ ν•΄μ„€ 보기", expanded=False): # Day X-1 λ‰΄μŠ€ ν•΄μ„€ 보기
491
- if st.session_state['news_meanings']:
492
- for i, meaning in st.session_state['news_meanings'].items():
493
- st.markdown(f"**λ‰΄μŠ€ {i+1}**:") # λ‰΄μŠ€ 번호 1λΆ€ν„° μ‹œμž‘ν•˜λ„λ‘ μˆ˜μ •
494
- st.write(meaning)
495
- else:
496
- st.info("μ–΄μ œ λ‰΄μŠ€μ— λŒ€ν•œ 해섀이 μ—†μŠ΅λ‹ˆλ‹€.")
 
497
 
498
  elif not st.session_state['daily_news']:
499
  st.info("λ‰΄μŠ€ 생성 λ²„νŠΌμ„ 눌러 였늘의 λ‰΄μŠ€λ₯Ό λ°›μ•„λ³΄μ„Έμš”.")
@@ -510,7 +429,7 @@ def main():
510
  st.markdown("---")
511
  menu = st.radio(
512
  "**메뉴 선택**",
513
- ('ν˜„μž¬ μ£Όκ°€', 'λ‚΄ 포트폴리였', '주식 맀수', '주식 맀도') # 'λ‰΄μŠ€ 뢄석 및 예츑' 제거
514
  )
515
  st.markdown("---")
516
  if st.button("ν•˜λ£¨ μ§€λ‚˜κΈ°", use_container_width=True, key='day_pass_button'):
@@ -578,6 +497,17 @@ def main():
578
  quantity_sell = st.number_input("맀도 μˆ˜λŸ‰ (μ£Ό):", min_value=1, max_value=max_sell_quantity, value=1, step=1)
579
  if st.button("주식 맀도", use_container_width=True, key='sell_button'):
580
  sell_stock(selected_stock_sell, quantity_sell)
 
 
 
 
 
 
 
 
 
 
 
581
 
582
 
583
  def display_portfolio_table():
@@ -603,8 +533,8 @@ def display_portfolio_table():
603
 
604
  stock_value = current_price * quantity
605
  purchase_value = purchase_price * quantity
606
- profit_loss = stock_value - portfolio['cash'] - total_purchase_value
607
- profit_rate = (profit_loss / purchase_value) * 100 if total_purchase_value != 0 else 0
608
  if total_purchase_value == 0:
609
  total_profit_rate = 0.0
610
  st.markdown(f"**총 평가앑:** {total_value:,.0f} 원")
 
19
  st.markdown(
20
  """
21
  <style>
22
+ /* Custom CSS remains the same */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  </style>
24
  """,
25
  unsafe_allow_html=True,
 
144
  if 'sector_news_impact' not in st.session_state:
145
  st.session_state['sector_news_impact'] = {} # 섹터별 λ‰΄μŠ€ 영ν–₯ μ €μž₯
146
 
147
+
148
  # --- λ‰΄μŠ€ 생성 ν•¨μˆ˜ ---
149
  def generate_news():
150
+ day_count = st.session_state['day_count']
151
  prompt = f"""
152
  **μ§€μ‹œ:**
153
  μ΄ˆλ“±ν•™μƒ 6ν•™λ…„ μˆ˜μ€€μ— λ§žμΆ°μ„œ, 주식 μ‹œμž₯κ³Ό κ²½μ œμ— κ΄€λ ¨λœ λ‰΄μŠ€ 기사 **5개**λ₯Ό μƒμ„±ν•΄μ£Όμ„Έμš”.
 
253
 
254
  sell_price = stock_price * quantity
255
  st.session_state['portfolio']['cash'] += sell_price
256
+ st.session_state['portfolio']['stocks'][stock_name]['quantity'] -= quantity
257
  if st.session_state['portfolio']['stocks'][stock_name]['quantity'] == 0:
258
  del st.session_state['portfolio']['stocks'][stock_name]
259
  st.session_state['messages'].append({"type": "success", "text": f"{stock_name} {quantity}μ£Ό 맀도 μ™„λ£Œ. 총 {sell_price:,.0f}원 νšλ“."})
 
405
  if st.session_state['previous_daily_news'] and st.session_state['news_meanings']:
406
  st.subheader(f"Day {st.session_state['day_count'] - 1} λ‰΄μŠ€ ν•΄μ„€") # Day X-1 λ‰΄μŠ€ ν•΄μ„€
407
  st.info("AIκ°€ λΆ„μ„ν•œ μ–΄μ œ λ‰΄μŠ€ ν•΄μ„€μž…λ‹ˆλ‹€.")
408
+ if st.session_state['news_meanings']: # Check if news_meanings is not empty
409
+ for i, meaning in st.session_state['news_meanings'].items():
410
+ st.markdown(f"**λ‰΄μŠ€ {i+1}**:") # λ‰΄μŠ€ 번호 1λΆ€ν„° μ‹œμž‘ν•˜λ„λ‘ μˆ˜μ •
411
+ st.write(meaning)
412
+ st.session_state['previous_daily_news'] = None # 해섀이 μƒμ„±λ˜λ©΄ previous_daily_news μ΄ˆκΈ°ν™”
413
+ st.session_state['news_meanings'] = {} # 해섀이 μƒμ„±λ˜λ©΄ news_meanings μ΄ˆκΈ°ν™”
414
+ else:
415
+ st.info("μ–΄μ œ λ‰΄μŠ€μ— λŒ€ν•œ 해섀이 μ—†μŠ΅λ‹ˆλ‹€.")
416
 
417
  elif not st.session_state['daily_news']:
418
  st.info("λ‰΄μŠ€ 생성 λ²„νŠΌμ„ 눌러 였늘의 λ‰΄μŠ€λ₯Ό λ°›μ•„λ³΄μ„Έμš”.")
 
429
  st.markdown("---")
430
  menu = st.radio(
431
  "**메뉴 선택**",
432
+ ('ν˜„μž¬ μ£Όκ°€', 'λ‚΄ 포트폴리였', '주식 맀수', '주식 맀도', 'μ–΄μ œ λ‰΄μŠ€ ν•΄μ„€') # 'λ‰΄μŠ€ 뢄석 및 예츑' 제거, 'μ–΄μ œ λ‰΄μŠ€ ν•΄μ„€' μΆ”κ°€
433
  )
434
  st.markdown("---")
435
  if st.button("ν•˜λ£¨ μ§€λ‚˜κΈ°", use_container_width=True, key='day_pass_button'):
 
497
  quantity_sell = st.number_input("맀도 μˆ˜λŸ‰ (μ£Ό):", min_value=1, max_value=max_sell_quantity, value=1, step=1)
498
  if st.button("주식 맀도", use_container_width=True, key='sell_button'):
499
  sell_stock(selected_stock_sell, quantity_sell)
500
+
501
+ elif menu == 'μ–΄μ œ λ‰΄μŠ€ ν•΄μ„€': # "μ–΄μ œ λ‰΄μŠ€ ν•΄μ„€" 메뉴 선택 μ‹œ
502
+ if st.session_state['previous_daily_news'] and st.session_state['news_meanings']: # ν•΄μ„€ 있으면 ν‘œμ‹œ
503
+ st.subheader(f"Day {st.session_state['day_count'] - 1} λ‰΄μŠ€ ν•΄μ„€") # Day X-1 λ‰΄μŠ€ ν•΄μ„€
504
+ st.info("AIκ°€ λΆ„μ„ν•œ μ–΄μ œ λ‰΄μŠ€ ν•΄μ„€μž…λ‹ˆλ‹€.")
505
+ for i, meaning in st.session_state['news_meanings'].items():
506
+ st.markdown(f"**λ‰΄μŠ€ {i+1}**:") # λ‰΄μŠ€ 번호 1λΆ€ν„° μ‹œμž‘
507
+ st.write(meaning)
508
+ else: # ν•΄μ„€ μ—†μœΌλ©΄ μ•ˆλ‚΄ λ©”μ‹œμ§€ ν‘œμ‹œ
509
+ st.info("이전 λ‰΄μŠ€ 해섀이 μ—†μŠ΅λ‹ˆλ‹€. ν•˜λ£¨ μ§€λ‚˜κ°€κΈ° λ²„νŠΌμ„ 눌러 λ‰΄μŠ€ 해섀을 λ°›μ•„λ³΄μ„Έμš”.")
510
+
511
 
512
 
513
  def display_portfolio_table():
 
533
 
534
  stock_value = current_price * quantity
535
  purchase_value = purchase_price * quantity
536
+ profit_loss = stock_value - purchase_value
537
+ profit_rate = (profit_loss / purchase_value) * 100 if purchase_value != 0 else 0
538
  if total_purchase_value == 0:
539
  total_profit_rate = 0.0
540
  st.markdown(f"**총 평가앑:** {total_value:,.0f} 원")