Update app.py
Browse files
app.py
CHANGED
|
@@ -19,90 +19,7 @@ st.set_page_config(
|
|
| 19 |
st.markdown(
|
| 20 |
"""
|
| 21 |
<style>
|
| 22 |
-
/*
|
| 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']
|
| 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
|
| 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 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
|
|
|
| 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 -
|
| 607 |
-
profit_rate = (profit_loss / purchase_value) * 100 if
|
| 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} μ")
|