Spaces:
Runtime error

ditgun commited on
Commit
c611e55
Β·
verified Β·
1 Parent(s): f9264a9

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +34 -24
src/app.py CHANGED
@@ -1063,7 +1063,7 @@ def get_scan_prompt(target, tid="", owned=None, news=None, portfolio_context="")
1063
  def get_owned_prompt(target, tid="", news=None, portfolio_context=""):
1064
  date_s = datetime.now().strftime("%Yλ…„ %mμ›” %d일")
1065
  news_s = ""
1066
- if news: news_s = "\n[졜근 λ‰΄μŠ€ β€” ν…Œμ œ μœ νš¨μ„± νŒλ‹¨μ— 반영]\n" + "\n".join(news)
1067
  port_s = f"\n{portfolio_context}" if portfolio_context else ""
1068
  return f"""[쀑μž₯κΈ° μ„±μž₯μ£Ό 보유 진단 μ „λ¬Έκ°€ β€” {date_s} / ID:{tid}_{random.randint(100,999)}]
1069
  {INVESTOR_PROFILE}
@@ -1353,8 +1353,8 @@ def render_owned_report(rpt, analyst_target_krw=0, current_price_krw=0):
1353
  )
1354
  render_confidence_bar(conf_score, conf_reason)
1355
 
1356
- # ── νƒ­ 뢄리: μš”μ•½ / ν…Œμ œ / μ•‘μ…˜ / λͺ©ν‘œκ°€
1357
- tab_sum, tab_thesis, tab_action, tab_target = st.tabs(["πŸ“‹ μš”μ•½", "πŸ” ν…Œμ œ", "⚑ μ•‘μ…˜", "🎯 λͺ©ν‘œκ°€"])
1358
 
1359
  # ─────────── νƒ­ 1: μš”μ•½ ───────────
1360
  with tab_sum:
@@ -1378,7 +1378,7 @@ def render_owned_report(rpt, analyst_target_krw=0, current_price_krw=0):
1378
  unsafe_allow_html=True
1379
  )
1380
 
1381
- # ─────────── νƒ­ 2: ν…Œμ œ ───────────
1382
  with tab_thesis:
1383
  thesis = rpt.get("thesis_validity", {})
1384
  if isinstance(thesis, dict):
@@ -1392,7 +1392,7 @@ def render_owned_report(rpt, analyst_target_krw=0, current_price_krw=0):
1392
  '<div style="background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.08); '
1393
  'border-radius:12px; padding:20px; margin-top:12px;">'
1394
  '<div style="font-size:14px; color:#888888; line-height:1.9; margin-bottom:12px;">'
1395
- '맀수 κ·Όκ±°λ₯Ό κΈ°λ‘ν•˜λ©΄ <b style="color:#EBEBEB;">ν…Œμ œ μœ νš¨μ„±</b>을 μ •ν™•νžˆ νŒλ‹¨ν•΄λ“œλ¦΄ 수 μžˆμ–΄μš”.'
1396
  '</div>'
1397
  '<div style="font-size:12px; color:#444444; background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.08); border-radius:8px; padding:10px 14px;">'
1398
  'πŸ’‘ 포트폴리였 λͺ©λ‘μ—μ„œ <b style="color:#D8D8D8;">β‹― νŽΈμ§‘</b>을 눌러 맀수 κ·Όκ±°λ₯Ό μΆ”κ°€ν•˜μ„Έμš”.'
@@ -1412,7 +1412,7 @@ def render_owned_report(rpt, analyst_target_krw=0, current_price_krw=0):
1412
  f'<div style="background:{verdict_bg}; border:1px solid {verdict_color}33; '
1413
  f'border-radius:12px; padding:16px; margin-top:12px;">'
1414
  f'<div style="display:flex; align-items:center; gap:10px; margin-bottom:14px;">'
1415
- f'<span style="font-size:10px; font-weight:700; color:#444444; letter-spacing:1px; text-transform:uppercase;">맀수 ν…Œμ œ μœ νš¨μ„±</span>'
1416
  f'<span style="font-size:13px; font-weight:900; color:{verdict_color}; background:{verdict_bg}; '
1417
  f'border:1px solid {verdict_color}55; padding:3px 12px; border-radius:20px;">{verdict}</span>'
1418
  f'</div>'
@@ -1592,7 +1592,7 @@ def render_scan_report(rpt, analyst_target_krw=0, current_price_krw=0):
1592
  f'<div style="font-size:9px; color:#444444; margin-bottom:6px; text-transform:uppercase; letter-spacing:1px;">2μ°¨ μΆ”κ°€λ§€μˆ˜</div>'
1593
  f'<div style="font-size:13px; font-weight:700; color:#D8D8D8;">{z2}</div></div>'
1594
  f'<div style="background:#0C0C0C; border-radius:8px; padding:14px; text-align:center;">'
1595
- f'<div style="font-size:9px; color:#444444; margin-bottom:6px; text-transform:uppercase; letter-spacing:1px;">ν…Œμ œ λΆ•κ΄΄μ„ </div>'
1596
  f'<div style="font-size:13px; font-weight:700; color:#E0E0E0;">{zs}</div></div>'
1597
  f'</div>',
1598
  unsafe_allow_html=True
@@ -1868,7 +1868,7 @@ def get_price_alert(action, current_price, target_price_str, avg_price, report=N
1868
  if ("보유" in action or "μΆ”κ°€λ§€μˆ˜" in action) and current_price < avg_price:
1869
  if verdict == "μ κ²€ν•„μš”":
1870
  loss_pct = (current_price / avg_price - 1) * 100
1871
- return 'sl', f"ν…Œμ œ μ κ²€ν•„μš” + 손싀 쀑 ({loss_pct:+.1f}%) Β· μž¬μ§„λ‹¨ ꢌμž₯"
1872
 
1873
  return None, None
1874
 
@@ -2666,7 +2666,7 @@ elif st.session_state.main_menu == "β–€ μžμ‚° 상세 진단":
2666
  '<div style="font-size:11px; font-weight:700; color:#D8D8D8; letter-spacing:1.5px; '
2667
  'text-transform:uppercase; margin-bottom:8px;">✏️ 맀수 κ·Όκ±° 미기둝</div>'
2668
  '<div style="font-size:13px; color:#888888; line-height:1.8; margin-bottom:12px;">'
2669
- '맀수 λ‹Ήμ‹œ 생각을 적어두면 <b style="color:#EBEBEB;">ν…Œμ œ μœ νš¨μ„±</b>을 μ •ν™•ν•˜κ²Œ νŒλ‹¨ν•  수 μžˆμ–΄μš”.'
2670
  '</div></div>',
2671
  unsafe_allow_html=True
2672
  )
@@ -2921,7 +2921,7 @@ elif st.session_state.main_menu == "β–€ μžμ‚° 상세 진단":
2921
  act = rp.get("action_type", "보유")
2922
  thesis = rp.get("thesis_validity", {})
2923
  verdict = thesis.get("verdict", "") if isinstance(thesis, dict) else ""
2924
- verdict_tag = f"/ν…Œμ œ:{verdict}" if verdict else ""
2925
  return f"- {row['μ’…λͺ©λͺ…']}({t}) [μ„Ήν„°:{sec}/Beta:{beta:.2f}]: 수읡λ₯ {pct:.1f}%, [μ „λž΅:{act}{verdict_tag}]"
2926
  return f"- {row['μ’…λͺ©λͺ…']}({t}): 수읡λ₯ {pct:.1f}%"
2927
 
@@ -2978,12 +2978,18 @@ elif st.session_state.main_menu == "β–€ μžμ‚° 상세 진단":
2978
  hc_name, hc_edit, hc_sell, hc_del = st.columns([0.67, 0.11, 0.11, 0.11], vertical_alignment="center")
2979
 
2980
  with hc_name:
2981
- tv_str = f" [{tv}]" if tv else ""
2982
- if st.button(
2983
- f"**{row['μ’…λͺ©λͺ…']}** `{t}`{tv_str}",
2984
- key=f"name_{idx}", use_container_width=True, help="μΉ΄λ“œμ΄λ™"
2985
- ):
2986
- st.session_state.detail_ticker = t; st.rerun()
 
 
 
 
 
 
2987
 
2988
  with hc_edit:
2989
  if st.button("✎", key=f"edit_btn_{idx}", use_container_width=True, help="νŽΈμ§‘"):
@@ -3002,15 +3008,19 @@ elif st.session_state.main_menu == "β–€ μžμ‚° 상세 진단":
3002
  st.session_state.df = st.session_state.df.drop(idx).reset_index(drop=True)
3003
  save_assets(); st.session_state.price_cache_ts = 0; st.rerun()
3004
 
3005
- # ── μΉ΄λ“œ λ³Έλ¬Έ (클릭 β†’ 상세 진단 이동)
3006
- tgp_str = f" Β· λͺ©ν‘œ {tgp}" if tgp != "-" else ""
3007
  preview = ("πŸ“Œ " + buy_reason[:42] + ("..." if len(buy_reason) > 42 else "")) if buy_reason else ""
3008
- body_label = (
3009
- f"평단 {int(ap):,}원 β†’ {ck:,}원 {pa} {abs(pct):.1f}%{tgp_str}\n"
3010
- f"[{act}]{' ' + preview if preview else ''}"
 
 
 
 
 
3011
  )
3012
- if st.button(body_label, key=f"body_{idx}", use_container_width=True, help="μΉ΄λ“œλ³Έλ¬Έ"):
3013
- st.session_state.detail_ticker = t; st.rerun()
3014
 
3015
  # ── 맀도 일지 폼 (↑ 클릭 μ‹œ 인라인 ν‘œμ‹œ)
3016
  if st.session_state.get(f"log_mode_{idx}", False):
@@ -3018,7 +3028,7 @@ elif st.session_state.main_menu == "β–€ μžμ‚° 상세 진단":
3018
  lc1, lc2 = st.columns(2)
3019
  with lc1: sp = st.number_input("맀도 단가(원)", value=float(ck), step=100.0, key=f"sp_{idx}")
3020
  with lc2: sq = st.number_input("맀도 μˆ˜λŸ‰", value=float(row['μˆ˜λŸ‰']), max_value=float(row['μˆ˜λŸ‰']), min_value=0.01, step=1.0, key=f"sq_{idx}")
3021
- tags = ["#λͺ©ν‘œκ°€λ„달_읡절","#ν…Œμ œλΆ•κ΄΄_μ†μ ˆ","#λΉ„μ€‘μ‘°μ ˆ","#λ‡Œλ™λ§€λ§€_λ°˜μ„±","#μΆ”μ„Έμ΄νƒˆ","#ν„΄μ–΄λΌμš΄λ“œ_μ‹€νŒ¨"]
3022
  stag = st.selectbox("μ „λž΅ νƒœκ·Έ", tags, key=f"tag_{idx}")
3023
  memo = st.text_input("볡기 λ©”λͺ¨", placeholder="예: μ„±μž₯ μŠ€ν† λ¦¬ ν›Όμ†μœΌλ‘œ μ†μ ˆ", key=f"memo_{idx}")
3024
  if st.button("일지 μ €μž₯", key=f"slog_{idx}", type="primary", use_container_width=True):
 
1063
  def get_owned_prompt(target, tid="", news=None, portfolio_context=""):
1064
  date_s = datetime.now().strftime("%Yλ…„ %mμ›” %d일")
1065
  news_s = ""
1066
+ if news: news_s = "\n[졜근 λ‰΄μŠ€ β€” ν•΄μž μœ νš¨μ„± νŒλ‹¨μ— 반영]\n" + "\n".join(news)
1067
  port_s = f"\n{portfolio_context}" if portfolio_context else ""
1068
  return f"""[쀑μž₯κΈ° μ„±μž₯μ£Ό 보유 진단 μ „λ¬Έκ°€ β€” {date_s} / ID:{tid}_{random.randint(100,999)}]
1069
  {INVESTOR_PROFILE}
 
1353
  )
1354
  render_confidence_bar(conf_score, conf_reason)
1355
 
1356
+ # ── νƒ­ 뢄리: μš”μ•½ / ν•΄μž / μ•‘μ…˜ / λͺ©ν‘œκ°€
1357
+ tab_sum, tab_thesis, tab_action, tab_target = st.tabs(["πŸ“‹ μš”μ•½", "πŸ” ν•΄μž", "⚑ μ•‘μ…˜", "🎯 λͺ©ν‘œκ°€"])
1358
 
1359
  # ─────────── νƒ­ 1: μš”μ•½ ───────────
1360
  with tab_sum:
 
1378
  unsafe_allow_html=True
1379
  )
1380
 
1381
+ # ─────────── νƒ­ 2: ν•΄μž ───────────
1382
  with tab_thesis:
1383
  thesis = rpt.get("thesis_validity", {})
1384
  if isinstance(thesis, dict):
 
1392
  '<div style="background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.08); '
1393
  'border-radius:12px; padding:20px; margin-top:12px;">'
1394
  '<div style="font-size:14px; color:#888888; line-height:1.9; margin-bottom:12px;">'
1395
+ '맀수 κ·Όκ±°λ₯Ό κΈ°λ‘ν•˜λ©΄ <b style="color:#EBEBEB;">ν•΄μž μœ νš¨μ„±</b>을 μ •ν™•νžˆ νŒλ‹¨ν•΄λ“œλ¦΄ 수 μžˆμ–΄μš”.'
1396
  '</div>'
1397
  '<div style="font-size:12px; color:#444444; background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.08); border-radius:8px; padding:10px 14px;">'
1398
  'πŸ’‘ 포트폴리였 λͺ©λ‘μ—μ„œ <b style="color:#D8D8D8;">β‹― νŽΈμ§‘</b>을 눌러 맀수 κ·Όκ±°λ₯Ό μΆ”κ°€ν•˜μ„Έμš”.'
 
1412
  f'<div style="background:{verdict_bg}; border:1px solid {verdict_color}33; '
1413
  f'border-radius:12px; padding:16px; margin-top:12px;">'
1414
  f'<div style="display:flex; align-items:center; gap:10px; margin-bottom:14px;">'
1415
+ f'<span style="font-size:10px; font-weight:700; color:#444444; letter-spacing:1px; text-transform:uppercase;">맀수 ν•΄μž μœ νš¨μ„±</span>'
1416
  f'<span style="font-size:13px; font-weight:900; color:{verdict_color}; background:{verdict_bg}; '
1417
  f'border:1px solid {verdict_color}55; padding:3px 12px; border-radius:20px;">{verdict}</span>'
1418
  f'</div>'
 
1592
  f'<div style="font-size:9px; color:#444444; margin-bottom:6px; text-transform:uppercase; letter-spacing:1px;">2μ°¨ μΆ”κ°€λ§€μˆ˜</div>'
1593
  f'<div style="font-size:13px; font-weight:700; color:#D8D8D8;">{z2}</div></div>'
1594
  f'<div style="background:#0C0C0C; border-radius:8px; padding:14px; text-align:center;">'
1595
+ f'<div style="font-size:9px; color:#444444; margin-bottom:6px; text-transform:uppercase; letter-spacing:1px;">ν•΄μž λΆ•κ΄΄μ„ </div>'
1596
  f'<div style="font-size:13px; font-weight:700; color:#E0E0E0;">{zs}</div></div>'
1597
  f'</div>',
1598
  unsafe_allow_html=True
 
1868
  if ("보유" in action or "μΆ”κ°€λ§€μˆ˜" in action) and current_price < avg_price:
1869
  if verdict == "μ κ²€ν•„μš”":
1870
  loss_pct = (current_price / avg_price - 1) * 100
1871
+ return 'sl', f"ν•΄μž μ κ²€ν•„μš” + 손싀 쀑 ({loss_pct:+.1f}%) Β· ��진단 ꢌμž₯"
1872
 
1873
  return None, None
1874
 
 
2666
  '<div style="font-size:11px; font-weight:700; color:#D8D8D8; letter-spacing:1.5px; '
2667
  'text-transform:uppercase; margin-bottom:8px;">✏️ 맀수 κ·Όκ±° 미기둝</div>'
2668
  '<div style="font-size:13px; color:#888888; line-height:1.8; margin-bottom:12px;">'
2669
+ '맀수 λ‹Ήμ‹œ 생각을 적어두면 <b style="color:#EBEBEB;">ν•΄μž μœ νš¨μ„±</b>을 μ •ν™•ν•˜κ²Œ νŒλ‹¨ν•  수 μžˆμ–΄μš”.'
2670
  '</div></div>',
2671
  unsafe_allow_html=True
2672
  )
 
2921
  act = rp.get("action_type", "보유")
2922
  thesis = rp.get("thesis_validity", {})
2923
  verdict = thesis.get("verdict", "") if isinstance(thesis, dict) else ""
2924
+ verdict_tag = f"/ν•΄μž:{verdict}" if verdict else ""
2925
  return f"- {row['μ’…λͺ©λͺ…']}({t}) [μ„Ήν„°:{sec}/Beta:{beta:.2f}]: 수읡λ₯ {pct:.1f}%, [μ „λž΅:{act}{verdict_tag}]"
2926
  return f"- {row['μ’…λͺ©λͺ…']}({t}): 수읡λ₯ {pct:.1f}%"
2927
 
 
2978
  hc_name, hc_edit, hc_sell, hc_del = st.columns([0.67, 0.11, 0.11, 0.11], vertical_alignment="center")
2979
 
2980
  with hc_name:
2981
+ tv_tag = (
2982
+ f'<span style="font-size:9px;color:{tv_color};background:{tv_color}15;'
2983
+ f'border:1px solid {tv_color}33;padding:1px 6px;border-radius:3px;margin-left:6px;">{tv}</span>'
2984
+ ) if tv else ""
2985
+ st.markdown(
2986
+ f'<div style="font-size:15px;font-weight:800;color:#EBEBEB;line-height:1.3;">'
2987
+ f'{row["μ’…λͺ©λͺ…"]} '
2988
+ f'<span style="font-size:10px;color:#D8D8D8;background:rgba(255,255,255,0.06);'
2989
+ f'padding:2px 6px;border-radius:4px;border:1px solid rgba(255,255,255,0.10);">{t}</span>'
2990
+ f'{tv_tag}</div>',
2991
+ unsafe_allow_html=True
2992
+ )
2993
 
2994
  with hc_edit:
2995
  if st.button("✎", key=f"edit_btn_{idx}", use_container_width=True, help="νŽΈμ§‘"):
 
3008
  st.session_state.df = st.session_state.df.drop(idx).reset_index(drop=True)
3009
  save_assets(); st.session_state.price_cache_ts = 0; st.rerun()
3010
 
3011
+ # ── μΉ΄λ“œ λ³Έλ¬Έ
3012
+ tgp_html = f"&nbsp;Β·&nbsp;<span style='color:#D8D8D8;'>λͺ©ν‘œ {tgp}</span>" if tgp != "-" else ""
3013
  preview = ("πŸ“Œ " + buy_reason[:42] + ("..." if len(buy_reason) > 42 else "")) if buy_reason else ""
3014
+ card_body = (
3015
+ f'<div style="margin:6px 0 2px;font-size:13px;color:#888888;">'
3016
+ f'평단 <b style="color:#EBEBEB;font-family:IBM Plex Mono,monospace;">{int(ap):,}</b>원 β†’ '
3017
+ f'<b style="color:{pc};font-family:IBM Plex Mono,monospace;">{ck:,}</b>원'
3018
+ f'&nbsp;<span style="font-size:12px;color:{pc};">{pa} {abs(pct):.1f}%</span>'
3019
+ f'{tgp_html}</div>'
3020
+ f'<div style="font-size:11px;color:#444444;margin-top:2px;">[{act}]'
3021
+ f'{"&nbsp;&nbsp;" + preview if preview else ""}</div>'
3022
  )
3023
+ st.markdown(card_body, unsafe_allow_html=True)
 
3024
 
3025
  # ── 맀도 일지 폼 (↑ 클릭 μ‹œ 인라인 ν‘œμ‹œ)
3026
  if st.session_state.get(f"log_mode_{idx}", False):
 
3028
  lc1, lc2 = st.columns(2)
3029
  with lc1: sp = st.number_input("맀도 단가(원)", value=float(ck), step=100.0, key=f"sp_{idx}")
3030
  with lc2: sq = st.number_input("맀도 μˆ˜λŸ‰", value=float(row['μˆ˜λŸ‰']), max_value=float(row['μˆ˜λŸ‰']), min_value=0.01, step=1.0, key=f"sq_{idx}")
3031
+ tags = ["#λͺ©ν‘œκ°€λ„달_읡절","#ν•΄μžλΆ•κ΄΄_μ†μ ˆ","#λΉ„μ€‘μ‘°μ ˆ","#λ‡Œλ™λ§€λ§€_λ°˜μ„±","#μΆ”μ„Έμ΄νƒˆ","#ν„΄μ–΄λΌμš΄λ“œ_μ‹€νŒ¨"]
3032
  stag = st.selectbox("μ „λž΅ νƒœκ·Έ", tags, key=f"tag_{idx}")
3033
  memo = st.text_input("볡기 λ©”λͺ¨", placeholder="예: μ„±μž₯ μŠ€ν† λ¦¬ ν›Όμ†μœΌλ‘œ μ†μ ˆ", key=f"memo_{idx}")
3034
  if st.button("일지 μ €μž₯", key=f"slog_{idx}", type="primary", use_container_width=True):