Spaces:
Runtime error

ditgun commited on
Commit
fdff697
Β·
verified Β·
1 Parent(s): 7df1c5e

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +242 -50
src/app.py CHANGED
@@ -780,10 +780,20 @@ def get_all_prices():
780
  # ============================================================
781
  REPO_ID = "ditgun/my-invest-db"
782
  DB_FILE = "my_assets_v30.csv"
783
- CACHE_FILE = "analysis_cache_v30.json"
784
  FAV_FILE = "my_fav_v30.csv"
785
  TRADE_FILE = "my_trades_v30.csv"
786
 
 
 
 
 
 
 
 
 
 
 
787
  def _hf_dl(fn):
788
  tok = os.getenv("HF_TOKEN")
789
  if not tok: return False
@@ -828,8 +838,30 @@ if 'full_stock_reports' not in st.session_state:
828
  try:
829
  with open(CACHE_FILE, "r", encoding="utf-8") as f:
830
  d = json.load(f)
831
- st.session_state.full_stock_reports = d.get("individual", {})
832
- st.session_state.p_diag_res = d.get("portfolio", None)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
833
  except:
834
  st.session_state.full_stock_reports = {}
835
  st.session_state.p_diag_res = None
@@ -892,6 +924,9 @@ def get_scan_prompt(target, tid="", owned=None, news=None):
892
  3. 쀑학생도 이해할 수 μžˆλŠ” μ‰¬μš΄ 말둜 μž‘μ„±.
893
  4. 각 ν•­λͺ©λ§ˆλ‹€ κ·Όκ±° 데이터 1개 이상 λͺ…μ‹œ.
894
  5. 순수 JSON만 좜λ ₯. λ§ˆν¬λ‹€μš΄ 기호 κΈˆμ§€.
 
 
 
895
  {news_s}
896
 
897
  [μ‹€μ œ 데이터]
@@ -899,19 +934,22 @@ def get_scan_prompt(target, tid="", owned=None, news=None):
899
  [이미 보유 쀑인 μ’…λͺ© β€” 쀑볡 μΆ”μ²œ κΈˆμ§€] {owned_s}
900
 
901
  [뢄석 ν•­λͺ© 및 μš°μ„ μˆœμœ„]
902
- 1μˆœμœ„ β€” μ„±μž₯ 지속성 & ν•΄μž: 맀좜/이읡 μ„±μž₯λ₯ μ΄ μ•žμœΌλ‘œλ„ μœ μ§€λ˜λŠ”κ°€?
903
- κ²½μŸμžκ°€ 6κ°œμ›”~1λ…„ μ•ˆμ— λ”°λΌμ˜¬ 수 μ—†λŠ” μ΄μœ κ°€ μžˆλŠ”κ°€?
904
- 이것이 μ„±μž₯주인가, ν„΄μ–΄λΌμš΄λ“œμ£ΌμΈκ°€ λͺ…ν™•νžˆ ꡬ뢄할 것.
 
 
905
 
906
- 2μˆœμœ„ β€” 쀑μž₯κΈ° μ§„μž… 타이밍: μ§€κΈˆ 듀어가도 λ˜λŠ”κ°€?
907
  MA50/MA200 μœ„μΉ˜, 52μ£Ό κ³ μ € λŒ€λΉ„ ν˜„μž¬ μœ„μΉ˜ κΈ°μ€€μœΌλ‘œ νŒλ‹¨.
908
- λΆ„ν• λ§€μˆ˜ ꡬ간 (1μ°¨/2μ°¨)을 μ›ν™”λ‘œ μ œμ‹œν•  것.
909
 
910
- 3μˆœμœ„ β€” λ°Έλ₯˜μ—μ΄μ…˜: μ„±μž₯μ£Ό κΈ°μ€€μœΌλ‘œ μ§€κΈˆ 가격이 합리적인가?
911
- λ‹¨μˆœ PER이 μ•„λ‹ˆλΌ μ„±μž₯λ₯  λŒ€λΉ„ 가격(PEG κ°œλ…)으둜 νŒλ‹¨.
912
- κ³ PER이어도 μ„±μž₯λ₯ μ΄ λ’·λ°›μΉ¨λ˜λ©΄ ν•©λ¦¬μ μž„μ„ λͺ…μ‹œ.
 
913
 
914
- 4μˆœμœ„ β€” 기술주 리슀크 ν—€μ§€: 기술주 집쀑 ν¬νŠΈν΄λ¦¬μ˜€μ— μΆ”κ°€ν–ˆμ„ λ•Œ
915
  금리/규제/μ„Ήν„° λ‘œν…Œμ΄μ…˜ λ¦¬μŠ€ν¬κ°€ μ–Όλ§ˆλ‚˜ μ»€μ§€λŠ”κ°€?
916
  ν—€μ§€ ν•„μš” 여뢀와 방법을 ꡬ체적으둜 μ œμ‹œ.
917
 
@@ -923,7 +961,8 @@ def get_scan_prompt(target, tid="", owned=None, news=None):
923
  "confidence_score": 0,
924
  "confidence_reason": "신뒰도 κ·Όκ±°",
925
 
926
- "growth_moat_analysis": "μ„±μž₯지속성&ν•΄μž 뢄석 (3~4λ¬Έμž₯, μ„±μž₯μ£Ό/ν„΄μ–΄λΌμš΄λ“œ ꡬ뢄 λͺ…μ‹œ, μ‚¬μš© 데이터 οΏ½οΏ½οΏ½μ‹œ)",
 
927
  "timing_entry_analysis": "쀑μž₯κΈ° μ§„μž… 타이밍 뢄석 (2~3λ¬Έμž₯)",
928
  "entry_zones": {{
929
  "first_buy": "1μ°¨ λΆ„ν• λ§€μˆ˜ 적정 κ°€κ²©λŒ€ (원화)",
@@ -964,15 +1003,21 @@ def get_owned_prompt(target, tid="", news=None):
964
  3. 쀑학생도 이해할 수 μžˆλŠ” μ‰¬μš΄ 말둜 μž‘μ„±.
965
  4. λ‹¨μˆœ μ£Όκ°€ ν•˜λ½μ€ μ†μ ˆ μ΄μœ κ°€ μ•„λ‹˜. μ„±μž₯ μŠ€ν† λ¦¬ λΆ•κ΄΄ μ—¬λΆ€λ‘œλ§Œ νŒλ‹¨.
966
  5. 순수 JSON만 좜λ ₯. λ§ˆν¬λ‹€μš΄ 기호 κΈˆμ§€.
 
 
 
967
  {news_s}
968
 
969
  [μ‹€μ œ 데이터 β€” 맀수 κ·Όκ±° 포함]
970
  {target}
971
 
972
  [뢄석 ν•­λͺ© 및 μš°μ„ μˆœμœ„]
973
- 1μˆœμœ„ β€” 맀수 ν…Œμ œ μœ νš¨μ„±: μœ„μ˜ [맀수 λ‹Ήμ‹œ κ·Όκ±°]와 μ§€κΈˆ 상황을 직접 λŒ€μ‘°ν•œλ‹€.
974
- μ„±μž₯λ₯ μ΄ κΊΎμ˜€λŠ”κ°€? ν•΄μžκ°€ ν›Όμ†λλŠ”κ°€? 경쟁 ꡬ도가 λ°”λ€Œμ—ˆλŠ”κ°€?
975
- ν…Œμ œκ°€ μ‚΄μ•„μžˆμœΌλ©΄ "유효", ν›Όμ†λμœΌλ©΄ "훼손", μ• λ§€ν•˜λ©΄ "점검 ν•„μš”"둜 νŒμ •.
 
 
 
976
 
977
  2μˆœμœ„ β€” ν˜„μž¬ μ•‘μ…˜ νŒλ‹¨: μ§€κΈˆ νŒ”μ•„μ•Ό ν•˜λ‚˜, λ³΄μœ ν•΄μ•Ό ν•˜λ‚˜.
978
  단, μ†μ ˆμ€ λ°˜λ“œμ‹œ ν…Œμ œ λΆ•κ΄΄ μ‹œμ—λ§Œ ꢌ고. λ‹¨μˆœ -10~20% ν•˜λ½μ€ 보유 μœ μ§€κ°€ 원칙.
@@ -997,7 +1042,9 @@ def get_owned_prompt(target, tid="", news=None):
997
  "thesis_validity": {{
998
  "verdict": "유효/훼손/μ κ²€ν•„μš” 쀑 ν•˜λ‚˜",
999
  "original_thesis": "맀수 λ‹Ήμ‹œ κ·Όκ±° μš”μ•½",
1000
- "current_status": "μ§€κΈˆ κ·Έ κ·Όκ±°κ°€ μ–΄λ–»κ²Œ λλŠ”μ§€ (3~4λ¬Έμž₯, μ‹€μ œ 숫자 λͺ…μ‹œ)"
 
 
1001
  }},
1002
  "action_analysis": "ν˜„μž¬ μ•‘μ…˜ νŒλ‹¨ (3λ¬Έμž₯, μ†μ ˆκΈ°μ€€μ€ λ°˜λ“œμ‹œ ν…Œμ œλΆ•κ΄΄ 쑰건으둜만)",
1003
  "additional_buy_analysis": {{
@@ -1037,6 +1084,8 @@ def get_portfolio_prompt(target, owned=None, sector_summary=None, beta_info=None
1037
  3. μ’…λͺ© κ°„ 관계, μ„Ήν„° 뢄포, 상관관계 뢄석에 집쀑할 것.
1038
  4. 쀑학생도 이해할 수 μžˆλŠ” μ‰¬μš΄ 말둜 μž‘μ„±.
1039
  5. 순수 JSON만 좜λ ₯. λ§ˆν¬λ‹€μš΄ 기호 κΈˆμ§€.
 
 
1040
 
1041
  [포트폴리였 데이터]
1042
  {target}
@@ -1057,9 +1106,11 @@ def get_portfolio_prompt(target, owned=None, sector_summary=None, beta_info=None
1057
  3μˆœμœ„ β€” 전체 수읡λ₯  전망: μ§€κΈˆ κ΅¬μ„±μœΌλ‘œ 6κ°œμ›” ν›„ κΈ°λŒ€ μˆ˜μ΅μ€?
1058
  λ‚™κ΄€/κΈ°λ³Έ/λΉ„κ΄€ 3κ°€μ§€ μ‹œλ‚˜λ¦¬μ˜€λ‘œ κ°„λ‹¨νžˆ μ œμ‹œ.
1059
 
1060
- 4μˆœμœ„ β€” 집쀑도 κ²½κ³ : ν•œ μ„Ήν„°/ν…Œλ§ˆμ— λ„ˆλ¬΄ λͺ°λ €μžˆμ§€ μ•Šμ€κ°€?
1061
- 기술주 비쀑이 X%이면 금리 인상 μ‹œ 포트폴리였 전체 타격 μ˜ˆμƒμΉ˜ μ œμ‹œ.
1062
- μ„±μž₯μ£Ό vs ν„΄μ–΄λΌμš΄λ“œ λΉ„μœ¨λ„ 점검.
 
 
1063
 
1064
  [좜λ ₯ JSON ν˜•μ‹]
1065
  {{
@@ -1085,7 +1136,8 @@ def get_portfolio_prompt(target, owned=None, sector_summary=None, beta_info=None
1085
  }},
1086
  "concentration_warning": {{
1087
  "tech_weight_pct": 0,
1088
- "warning_message": "집쀑도 κ²½κ³  λ©”μ‹œμ§€",
 
1089
  "growth_vs_turnaround": "μ„±μž₯μ£Ό vs ν„΄μ–΄λΌμš΄λ“œ λΉ„μœ¨ 평가"
1090
  }},
1091
  "rebalancing_recommendations": [
@@ -1211,13 +1263,35 @@ def render_scan_report(rpt, analyst_target_krw=0, current_price_krw=0):
1211
  )
1212
 
1213
  # 1μˆœμœ„: μ„±μž₯ 지속성 & ν•΄μž
1214
- growth_moat = rpt.get("growth_moat_analysis", "")
1215
- if growth_moat:
1216
- safe = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', str(growth_moat).replace('\n','<br>'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1217
  st.markdown(
1218
  f'<div class="report-section">'
1219
  f'<div class="analysis-header">1μˆœμœ„ Β· μ„±μž₯ 지속성 & ν•΄μž</div>'
1220
- f'<div class="analysis-content">{safe}</div></div>',
1221
  unsafe_allow_html=True
1222
  )
1223
 
@@ -1337,27 +1411,87 @@ def render_owned_report(rpt, analyst_target_krw=0, current_price_krw=0):
1337
  verdict = thesis.get("verdict", "μ κ²€ν•„μš”")
1338
  orig = thesis.get("original_thesis", "")
1339
  curr = thesis.get("current_status", "")
1340
- verdict_color = {"유효": "#4ADE80", "훼손": "#E53E3E", "μ κ²€ν•„μš”": "#EAB308"}.get(verdict, "#8B98B4")
1341
- verdict_bg = {"유효": "rgba(74,222,128,0.08)", "훼손": "rgba(229,62,62,0.08)", "μ κ²€ν•„μš”": "rgba(234,179,8,0.08)"}.get(verdict, "rgba(255,255,255,0.04)")
1342
- safe_curr = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', str(curr).replace('\n','<br>'))
1343
 
1344
- st.markdown(
1345
- f'<div style="background:{verdict_bg}; border:1px solid {verdict_color}33; '
1346
- f'border-radius:12px; padding:20px; margin-bottom:14px;">'
1347
- f'<div style="display:flex; align-items:center; gap:10px; margin-bottom:14px;">'
1348
- f'<div class="analysis-header" style="margin-bottom:0;">1μˆœμœ„ Β· 맀수 ν…Œμ œ μœ νš¨μ„±</div>'
1349
- f'<span style="font-size:13px; font-weight:900; color:{verdict_color}; '
1350
- f'background:{verdict_bg}; border:1px solid {verdict_color}55; '
1351
- f'padding:3px 12px; border-radius:20px;">{verdict}</span>'
1352
- f'</div>'
1353
- f'<div style="background:rgba(0,0,0,0.2); border-radius:8px; padding:12px; margin-bottom:10px;">'
1354
- f'<div style="font-size:10px; color:#4A5568; margin-bottom:4px; text-transform:uppercase; letter-spacing:1px;">맀수 λ‹Ήμ‹œ κ·Όκ±°</div>'
1355
- f'<div style="font-size:13px; color:#8B98B4;">{orig}</div>'
1356
- f'</div>'
1357
- f'<div style="font-size:14px; color:#8B98B4; line-height:1.8;">{safe_curr}</div>'
1358
- f'</div>',
1359
- unsafe_allow_html=True
1360
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1361
 
1362
  # 2μˆœμœ„: ν˜„μž¬ μ•‘μ…˜
1363
  action_analysis = rpt.get("action_analysis", "")
@@ -1550,10 +1684,33 @@ def render_portfolio_report(rpt):
1550
  # 4μˆœμœ„: 집쀑도 κ²½κ³ 
1551
  conc = rpt.get("concentration_warning", {})
1552
  if isinstance(conc, dict):
1553
- tech_w = conc.get("tech_weight_pct", 0)
1554
- warn_m = conc.get("warning_message", "")
1555
- gvt = conc.get("growth_vs_turnaround", "")
 
 
1556
  tech_color = "#E53E3E" if tech_w >= 70 else ("#EAB308" if tech_w >= 50 else "#4ADE80")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1557
  st.markdown(
1558
  f'<div style="background:#0F1623; border:1px solid rgba(255,255,255,0.07); '
1559
  f'border-radius:10px; padding:16px; margin-bottom:14px;">'
@@ -1566,8 +1723,8 @@ def render_portfolio_report(rpt):
1566
  f'<div style="background:rgba(255,255,255,0.04); border-radius:6px; height:8px; flex:1;">'
1567
  f'<div style="background:{tech_color}; width:{min(tech_w,100)}%; height:8px; border-radius:6px;"></div>'
1568
  f'</div></div>'
1569
- f'<div style="font-size:13px; color:#8B98B4; margin-bottom:8px;">{warn_m}</div>'
1570
- f'{"<div style=\'background:#080C14;border-radius:6px;padding:8px 12px;font-size:12px;color:#8B98B4;\'><b style=\'color:#4A5568;\'>μ„±μž₯μ£Ό vs ν„΄μ–΄λΌμš΄λ“œ Β· </b>" + gvt + "</div>" if gvt else ""}'
1571
  f'</div>',
1572
  unsafe_allow_html=True
1573
  )
@@ -2317,6 +2474,41 @@ elif st.session_state.main_menu == "β–€ μžμ‚° 상세 진단":
2317
  holding_days = f"{(datetime.now() - bd).days}일"
2318
  except: pass
2319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2320
  if needs:
2321
  with st.spinner(f"{n} 보유 μ’…λͺ© 진단 쀑..."):
2322
  fin_ctx, has_rich = get_rich_financial_context(dt)
 
780
  # ============================================================
781
  REPO_ID = "ditgun/my-invest-db"
782
  DB_FILE = "my_assets_v30.csv"
783
+ CACHE_FILE = "analysis_cache_v31.json" # v31: λͺ¨λ“œλ³„ 뢄리 ν”„λ‘¬ν”„νŠΈ ꡬ쑰
784
  FAV_FILE = "my_fav_v30.csv"
785
  TRADE_FILE = "my_trades_v30.csv"
786
 
787
+ # μƒˆ λ³΄μœ μ§„λ‹¨ κ΅¬μ‘°μ—μ„œ λ°˜λ“œμ‹œ μžˆμ–΄μ•Ό ν•  ν•„λ“œ
788
+ _NEW_REPORT_FIELDS = {"thesis_validity", "action_analysis", "additional_buy_analysis", "target_remaining"}
789
+
790
+ def _is_new_structure(report: dict) -> bool:
791
+ """ꡬ ꡬ쑰(target_price, value_growth_analysis λ“±)인지 μƒˆ ꡬ쑰인지 νŒλ³„"""
792
+ if not isinstance(report, dict):
793
+ return False
794
+ # μƒˆ ꡬ쑰 ν•„λ“œ 쀑 ν•˜λ‚˜λΌλ„ 있으면 μƒˆ ꡬ쑰둜 νŒμ •
795
+ return bool(_NEW_REPORT_FIELDS & report.keys())
796
+
797
  def _hf_dl(fn):
798
  tok = os.getenv("HF_TOKEN")
799
  if not tok: return False
 
838
  try:
839
  with open(CACHE_FILE, "r", encoding="utf-8") as f:
840
  d = json.load(f)
841
+
842
+ raw_individual = d.get("individual", {})
843
+ raw_portfolio = d.get("portfolio", None)
844
+
845
+ # ── ꡬ ꡬ쑰 μΊμ‹œ μžλ™ λ¬΄νš¨ν™” ─────────────────────────
846
+ cleaned = {}
847
+ purged = 0
848
+ for key, val in raw_individual.items():
849
+ rpt = val.get("report", {}) if isinstance(val, dict) else {}
850
+ if _is_new_structure(rpt):
851
+ cleaned[key] = val
852
+ else:
853
+ purged += 1
854
+
855
+ st.session_state.full_stock_reports = cleaned
856
+
857
+ if raw_portfolio and _is_new_structure(raw_portfolio):
858
+ st.session_state.p_diag_res = raw_portfolio
859
+ else:
860
+ st.session_state.p_diag_res = None
861
+
862
+ if purged > 0:
863
+ st.toast(f"뢄석 ꡬ쑰 μ—…λ°μ΄νŠΈ: {purged}개 μ’…λͺ©μ„ μž¬λΆ„μ„ν•©λ‹ˆλ‹€.", icon="πŸ”„")
864
+
865
  except:
866
  st.session_state.full_stock_reports = {}
867
  st.session_state.p_diag_res = None
 
924
  3. 쀑학생도 이해할 수 μžˆλŠ” μ‰¬μš΄ 말둜 μž‘μ„±.
925
  4. 각 ν•­λͺ©λ§ˆλ‹€ κ·Όκ±° 데이터 1개 이상 λͺ…μ‹œ.
926
  5. 순수 JSON만 좜λ ₯. λ§ˆν¬λ‹€μš΄ 기호 κΈˆμ§€.
927
+ 6. μ •λŸ‰(숫자) 근거와 μ •μ„±(νŒλ‹¨) κ·Όκ±°λ₯Ό λ°˜λ“œμ‹œ λΆ„λ¦¬ν•΄μ„œ μ œμ‹œ.
928
+ μ •λŸ‰: λ§€μΆœμ„±μž₯λ₯ , μ˜μ—…μ΄μ΅λ₯ , PER, λΆ€μ±„λΉ„μœ¨ λ“± μ‹€μ œ 수치
929
+ μ •μ„±: 기술 ν•΄μž, λΈŒλžœλ“œ, κ²½μ˜μ§„ 신뒰도, μ‹œμž₯ ν¬μ§€μ…˜ λ³€ν™” λ“± νŒλ‹¨ κ·Όκ±°
930
  {news_s}
931
 
932
  [μ‹€μ œ 데이터]
 
934
  [이미 보유 쀑인 μ’…λͺ© β€” 쀑볡 μΆ”μ²œ κΈˆμ§€] {owned_s}
935
 
936
  [뢄석 ν•­λͺ© 및 μš°μ„ μˆœμœ„]
937
+ 1μˆœμœ„ β€” μ„±μž₯ 지속성 & ν•΄μž (μ •λŸ‰ + μ •μ„± 뢄리 ν•„μˆ˜):
938
+ [μ •λŸ‰] 맀좜/μ˜μ—…μ΄μ΅ μ„±μž₯λ₯ , 맀좜총이읡λ₯  좔이, R&D 투자 비쀑
939
+ [μ •μ„±] 이 νšŒμ‚¬λ§Œ κ°€μ§„ 기술/νŠΉν—ˆ/λ„€νŠΈμ›Œν¬ νš¨κ³Όκ°€ μ‹€μ œλ‘œ μžˆλŠ”κ°€?
940
+ κ²½μŸμžκ°€ 6κ°œμ›”~1λ…„ μ•ˆμ— λ”°λΌμ˜¬ 수 μ—†λŠ” ꡬ쑰적 μ΄μœ λŠ” 무엇인가?
941
+ 이것이 μ„±μž₯주인가, ν„΄μ–΄λΌμš΄λ“œμ£ΌμΈκ°€ λͺ…ν™•νžˆ ꡬ뢄.
942
 
943
+ 2μˆœμœ„ β€” 쀑μž₯κΈ° μ§„μž… 타이밍:
944
  MA50/MA200 μœ„μΉ˜, 52μ£Ό κ³ μ € λŒ€λΉ„ ν˜„μž¬ μœ„μΉ˜ κΈ°μ€€μœΌλ‘œ νŒλ‹¨.
945
+ λΆ„ν• λ§€μˆ˜ ꡬ간 (1μ°¨/2μ°¨)을 μ›ν™”λ‘œ μ œμ‹œ.
946
 
947
+ 3μˆœμœ„ β€” λ°Έλ₯˜μ—μ΄μ…˜ (μ •λŸ‰ + μ •μ„± 뢄리 ν•„μˆ˜):
948
+ [μ •λŸ‰] PER, PEG, PSR λ“± μ‹€μ œ 수치 기반
949
+ [μ •μ„±] 이 프리미엄이 μ •λ‹Ήν•œκ°€? μ‹œμž₯이 이 νšŒμ‚¬μ˜ μ–΄λ–€ κ°€μΉ˜λ₯Ό λ―Ώκ³  μžˆλŠ”κ°€?
950
+ κ³ PER이어도 μ„±μž₯λ₯ μ΄ λ’·λ°›μΉ¨λ˜λ©΄ ν•©λ¦¬μ μž„μ„ λͺ…μ‹œ.
951
 
952
+ 4μˆœμœ„ β€” 기술주 리슀크 ν—€μ§€:
953
  금리/규제/μ„Ήν„° λ‘œν…Œμ΄μ…˜ λ¦¬μŠ€ν¬κ°€ μ–Όλ§ˆλ‚˜ μ»€μ§€λŠ”κ°€?
954
  ν—€μ§€ ν•„μš” 여뢀와 방법을 ꡬ체적으둜 μ œμ‹œ.
955
 
 
961
  "confidence_score": 0,
962
  "confidence_reason": "신뒰도 κ·Όκ±°",
963
 
964
+ "growth_moat_quantitative": "μ •λŸ‰ κ·Όκ±°: λ§€μΆœμ„±μž₯λ₯ , μ˜μ—…μ΄μ΅λ₯ , R&D비쀑 λ“± μ‹€μ œ 수치 쀑심 뢄석 (2~3λ¬Έμž₯)",
965
+ "growth_moat_qualitative": "μ •μ„± κ·Όκ±°: κΈ°μˆ ν•΄μž, νŠΉν—ˆ, λ„€νŠΈμ›Œν¬νš¨κ³Ό, κ²½μ˜μ§„ 신뒰도, μ‹œμž₯ν¬μ§€μ…˜ λ³€ν™” λ“± νŒλ‹¨ 쀑심 뢄석 (2~3λ¬Έμž₯, μ„±μž₯μ£Ό/ν„΄μ–΄λΌμš΄λ“œ ꡬ뢄 λͺ…μ‹œ)",
966
  "timing_entry_analysis": "쀑μž₯κΈ° μ§„μž… 타이밍 뢄석 (2~3λ¬Έμž₯)",
967
  "entry_zones": {{
968
  "first_buy": "1μ°¨ λΆ„ν• λ§€μˆ˜ 적정 κ°€κ²©λŒ€ (원화)",
 
1003
  3. 쀑학생도 이해할 수 μžˆλŠ” μ‰¬μš΄ 말둜 μž‘μ„±.
1004
  4. λ‹¨μˆœ μ£Όκ°€ ν•˜λ½μ€ μ†μ ˆ μ΄μœ κ°€ μ•„λ‹˜. μ„±μž₯ μŠ€ν† λ¦¬ λΆ•κ΄΄ μ—¬λΆ€λ‘œλ§Œ νŒλ‹¨.
1005
  5. 순수 JSON만 좜λ ₯. λ§ˆν¬λ‹€μš΄ 기호 κΈˆμ§€.
1006
+ 6. ν…Œμ œ μœ νš¨μ„± νŒλ‹¨ μ‹œ μ •λŸ‰(숫자 λ³€ν™”)κ³Ό μ •μ„±(ꡬ쑰 λ³€ν™”) κ·Όκ±°λ₯Ό λ°˜λ“œμ‹œ 뢄리.
1007
+ μ •λŸ‰: μ„±μž₯λ₯  κΊΎμž„, 이읡λ₯  ν•˜λ½, 뢀채 증가 λ“± 수치 λ³€ν™”
1008
+ μ •μ„±: 경쟁 ꡬ도 λ³€ν™”, κ²½μ˜μ§„ μ „λž΅ μ„ νšŒ, 핡심 인물 μ΄νƒˆ, μ‹œμž₯ μ‹ λ’° λ³€ν™”
1009
  {news_s}
1010
 
1011
  [μ‹€μ œ 데이터 β€” 맀수 κ·Όκ±° 포함]
1012
  {target}
1013
 
1014
  [뢄석 ν•­λͺ© 및 μš°μ„ μˆœμœ„]
1015
+ 1μˆœμœ„ β€” 맀수 ν…Œμ œ μœ νš¨μ„± (μ •λŸ‰ + μ •μ„± 뢄리 ν•„μˆ˜):
1016
+ μœ„μ˜ [맀수 λ‹Ήμ‹œ κ·Όκ±°]와 μ§€κΈˆ 상황을 직접 λŒ€μ‘°ν•œλ‹€.
1017
+ [μ •λŸ‰] μ„±μž₯λ₯ μ΄ κΊΎμ˜€λŠ”κ°€? μ˜μ—…μ΄μ΅λ₯ μ΄ ν•˜λ½ν–ˆλŠ”κ°€? μ‹€μ œ 수치둜 확인.
1018
+ [μ •μ„±] ν•΄μžκ°€ ν›Όμ†λλŠ”κ°€? 경쟁 ꡬ도가 λ°”λ€Œμ—ˆλŠ”κ°€? κ²½μ˜μ§„ μ „λž΅μ΄ μ„ νšŒν–ˆλŠ”κ°€?
1019
+ μ‹œμž₯μ—μ„œ 이 νšŒμ‚¬μ— λŒ€ν•œ μ‹ λ’°κ°€ μœ μ§€λ˜κ³  μžˆλŠ”κ°€?
1020
+ ν…Œμ œκ°€ μ‚΄μ•„μžˆμœΌλ©΄ "유효", ν›Όμ†λμœΌλ©΄ "훼손", μ• λ§€ν•˜λ©΄ "μ κ²€ν•„μš”"둜 νŒμ •.
1021
 
1022
  2μˆœμœ„ β€” ν˜„μž¬ μ•‘μ…˜ νŒλ‹¨: μ§€κΈˆ νŒ”μ•„μ•Ό ν•˜λ‚˜, λ³΄μœ ν•΄μ•Ό ν•˜λ‚˜.
1023
  단, μ†μ ˆμ€ λ°˜λ“œμ‹œ ν…Œμ œ λΆ•κ΄΄ μ‹œμ—λ§Œ ꢌ고. λ‹¨μˆœ -10~20% ν•˜λ½μ€ 보유 μœ μ§€κ°€ 원칙.
 
1042
  "thesis_validity": {{
1043
  "verdict": "유효/훼손/μ κ²€ν•„μš” 쀑 ν•˜λ‚˜",
1044
  "original_thesis": "맀수 λ‹Ήμ‹œ κ·Όκ±° μš”μ•½",
1045
+ "quantitative_check": "μ •λŸ‰ 점검: μ„±μž₯λ₯ Β·μ΄μ΅λ₯ Β·λΆ€μ±„ λ“± 수치 λ³€ν™” (2~3λ¬Έμž₯, μ‹€μ œ 숫자 λͺ…μ‹œ)",
1046
+ "qualitative_check": "μ •μ„± 점검: κ²½μŸκ΅¬λ„Β·κ²½μ˜μ§„Β·ν•΄μžΒ·μ‹œμž₯μ‹ λ’° λ³€ν™” (2~3λ¬Έμž₯)",
1047
+ "current_status": "μ΅œμ’… νŒμ • μš”μ•½: μœ„ μ •λŸ‰+정성을 μ’…ν•©ν•΄ ν…Œμ œκ°€ μ–΄λ–€ μƒνƒœμΈμ§€ (2λ¬Έμž₯)"
1048
  }},
1049
  "action_analysis": "ν˜„μž¬ μ•‘μ…˜ νŒλ‹¨ (3λ¬Έμž₯, μ†μ ˆκΈ°μ€€μ€ λ°˜λ“œμ‹œ ν…Œμ œλΆ•κ΄΄ 쑰건으둜만)",
1050
  "additional_buy_analysis": {{
 
1084
  3. μ’…λͺ© κ°„ 관계, μ„Ήν„° 뢄포, 상관관계 뢄석에 집쀑할 것.
1085
  4. 쀑학생도 이해할 수 μžˆλŠ” μ‰¬μš΄ 말둜 μž‘μ„±.
1086
  5. 순수 JSON만 좜λ ₯. λ§ˆν¬λ‹€μš΄ 기호 κΈˆμ§€.
1087
+ 6. μ„Ήν„°κ°€ 달라도 동일 ν…Œλ§ˆ(예: AI 수혜, 금리 민감)에 묢인 μ’…λͺ©μ€ λ°˜λ“œμ‹œ 식별.
1088
+ μ •λŸ‰ 집쀑도(μ„Ήν„° 비쀑 %)와 μ •μ„± 집쀑도(ν…Œλ§ˆ 쀑볡)λ₯Ό λͺ¨λ‘ 진단할 것.
1089
 
1090
  [포트폴리였 데이터]
1091
  {target}
 
1106
  3μˆœμœ„ β€” 전체 수읡λ₯  전망: μ§€κΈˆ κ΅¬μ„±μœΌλ‘œ 6κ°œμ›” ν›„ κΈ°λŒ€ μˆ˜μ΅μ€?
1107
  λ‚™κ΄€/κΈ°λ³Έ/λΉ„κ΄€ 3κ°€μ§€ μ‹œλ‚˜λ¦¬μ˜€λ‘œ κ°„λ‹¨νžˆ μ œμ‹œ.
1108
 
1109
+ 4μˆœμœ„ β€” 집쀑도 κ²½κ³  (μ •λŸ‰ + μ •μ„± 뢄리 ν•„μˆ˜):
1110
+ [μ •λŸ‰] 기술주 비쀑이 X%이면 금리 인상 μ‹œ 포트폴리였 전체 타격 μ˜ˆμƒμΉ˜ μ œμ‹œ.
1111
+ μ„±μž₯μ£Ό vs ν„΄μ–΄λΌμš΄λ“œ λΉ„μœ¨λ„ 수치둜 점검.
1112
+ [μ •μ„±] μ„Ήν„°λŠ” 달라도 μ‹€μ§ˆμ μœΌλ‘œ 같은 ν…Œλ§ˆ(AI 수혜·금리 민감·쀑ꡭ μ΅μŠ€ν¬μ € λ“±)에
1113
+ 묢인 μ’…λͺ©λ“€μ„ 식별. μˆ«μžλ‘œλŠ” 뢄산돼 보여도 μ‹€μ œλ‘œλŠ” 집쀑인 경우λ₯Ό λ°˜λ“œμ‹œ μ§šμ„ 것.
1114
 
1115
  [좜λ ₯ JSON ν˜•μ‹]
1116
  {{
 
1136
  }},
1137
  "concentration_warning": {{
1138
  "tech_weight_pct": 0,
1139
+ "quantitative_concentration": "μ •λŸ‰ 집쀑도: 섹터별 비쀑 % 및 금리 인상 μ‹œ μ˜ˆμƒ 타격 (2λ¬Έμž₯)",
1140
+ "qualitative_concentration": "μ •μ„± 집쀑도: μ„Ήν„°κ°€ 달라도 μ‹€μ§ˆ 같은 ν…Œλ§ˆμ— 묢인 μ’…λͺ© 식별 (2~3λ¬Έμž₯)",
1141
  "growth_vs_turnaround": "μ„±μž₯μ£Ό vs ν„΄μ–΄λΌμš΄λ“œ λΉ„μœ¨ 평가"
1142
  }},
1143
  "rebalancing_recommendations": [
 
1263
  )
1264
 
1265
  # 1μˆœμœ„: μ„±μž₯ 지속성 & ν•΄μž
1266
+ growth_quant = rpt.get("growth_moat_quantitative", "")
1267
+ growth_qual = rpt.get("growth_moat_qualitative", "")
1268
+ # ꡬ버전 μΊμ‹œ ν˜Έν™˜
1269
+ if not growth_quant and not growth_qual:
1270
+ growth_quant = rpt.get("growth_moat_analysis", "")
1271
+ if growth_quant or growth_qual:
1272
+ safe_q = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', str(growth_quant).replace('\n','<br>'))
1273
+ safe_ql = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', str(growth_qual).replace('\n','<br>'))
1274
+ inner = ""
1275
+ if safe_q:
1276
+ inner += (
1277
+ f'<div style="background:rgba(0,0,0,0.2); border-radius:8px; padding:12px; margin-bottom:8px;">'
1278
+ f'<div style="font-size:9px; color:#4A5568; margin-bottom:6px; text-transform:uppercase; '
1279
+ f'letter-spacing:1.5px;">πŸ“Š μ •λŸ‰ κ·Όκ±°</div>'
1280
+ f'<div class="analysis-content" style="margin:0;">{safe_q}</div>'
1281
+ f'</div>'
1282
+ )
1283
+ if safe_ql:
1284
+ inner += (
1285
+ f'<div style="background:rgba(0,0,0,0.2); border-radius:8px; padding:12px;">'
1286
+ f'<div style="font-size:9px; color:#8B98B4; margin-bottom:6px; text-transform:uppercase; '
1287
+ f'letter-spacing:1.5px;">πŸ’‘ μ •μ„± νŒλ‹¨</div>'
1288
+ f'<div class="analysis-content" style="margin:0;">{safe_ql}</div>'
1289
+ f'</div>'
1290
+ )
1291
  st.markdown(
1292
  f'<div class="report-section">'
1293
  f'<div class="analysis-header">1μˆœμœ„ Β· μ„±μž₯ 지속성 & ν•΄μž</div>'
1294
+ f'{inner}</div>',
1295
  unsafe_allow_html=True
1296
  )
1297
 
 
1411
  verdict = thesis.get("verdict", "μ κ²€ν•„μš”")
1412
  orig = thesis.get("original_thesis", "")
1413
  curr = thesis.get("current_status", "")
 
 
 
1414
 
1415
+ # ── B. 맀수 κ·Όκ±° 미기둝 β†’ "확인 λΆˆκ°€" μƒνƒœ λΆ€λ“œλŸ¬μš΄ μ•ˆλ‚΄ ──
1416
+ no_reason = (not orig or "미기둝" in orig or "확인 λΆˆκ°€" in orig)
1417
+ if no_reason:
1418
+ st.markdown(
1419
+ '<div style="background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.08); '
1420
+ 'border-radius:12px; padding:20px; margin-bottom:14px;">'
1421
+ '<div style="display:flex; align-items:center; gap:10px; margin-bottom:12px;">'
1422
+ '<div class="analysis-header" style="margin-bottom:0;">1μˆœμœ„ Β· 맀수 ν…Œμ œ μœ νš¨μ„±</div>'
1423
+ '<span style="font-size:12px; font-weight:700; color:#4A5568; '
1424
+ 'background:rgba(255,255,255,0.04); border:1px solid rgba(255,255,255,0.08); '
1425
+ 'padding:3px 12px; border-radius:20px;">근거 미기둝</span>'
1426
+ '</div>'
1427
+ '<div style="font-size:14px; color:#8B98B4; line-height:1.9; margin-bottom:14px;">'
1428
+ '맀수 λ‹Ήμ‹œ 생각을 기둝해두면 <b style="color:#EEF2F7;">μ§€κΈˆ οΏ½οΏ½ μ΄μœ κ°€ μ‚΄μ•„μžˆλŠ”μ§€</b>λ₯Ό '
1429
+ 'μ •ν™•ν•˜κ²Œ νŒλ‹¨ν•΄λ“œλ¦΄ 수 μžˆμ–΄μš”.<br>'
1430
+ '재무 데이터 기반 뢄석은 μ•„λž˜μ—μ„œ ν™•μΈν•˜μ‹€ 수 μžˆμ§€λ§Œ, '
1431
+ '"λ‚΄κ°€ μ™œ μƒ€λŠ”κ°€"μ™€μ˜ λΉ„κ΅λŠ” 이번 λΆ„μ„μ—μ„œ λΉ μ‘ŒμŠ΅λ‹ˆλ‹€.'
1432
+ '</div>'
1433
+ '<div style="font-size:12px; color:#4A5568; '
1434
+ 'background:rgba(201,168,76,0.04); border:1px solid rgba(201,168,76,0.12); '
1435
+ 'border-radius:8px; padding:10px 14px;">'
1436
+ 'πŸ’‘ 포트폴리였 λͺ©λ‘μ—μ„œ <b style="color:#C9A84C;">✎ νŽΈμ§‘</b>을 눌러 맀수 κ·Όκ±°λ₯Ό μΆ”κ°€ν•˜λ©΄, '
1437
+ 'λ‹€μŒ 뢄석뢀터 ν…Œμ œ μœ νš¨μ„±μ„ μ •ν™•ν•˜κ²Œ νŒλ‹¨ν•  수 μžˆμ–΄μš”.'
1438
+ '</div>'
1439
+ '</div>',
1440
+ unsafe_allow_html=True
1441
+ )
1442
+ else:
1443
+ verdict_color = {"유효": "#4ADE80", "훼손": "#E53E3E", "μ κ²€ν•„μš”": "#EAB308"}.get(verdict, "#8B98B4")
1444
+ verdict_bg = {"유효": "rgba(74,222,128,0.08)", "훼손": "rgba(229,62,62,0.08)", "μ κ²€ν•„μš”": "rgba(234,179,8,0.08)"}.get(verdict, "rgba(255,255,255,0.04)")
1445
+ quant_chk = thesis.get("quantitative_check", "")
1446
+ qual_chk = thesis.get("qualitative_check", "")
1447
+ safe_curr = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', str(curr).replace('\n','<br>'))
1448
+ safe_qn = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', str(quant_chk).replace('\n','<br>'))
1449
+ safe_ql = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', str(qual_chk).replace('\n','<br>'))
1450
+
1451
+ # μ •λŸ‰/μ •μ„± 뢄리 블둝
1452
+ check_blocks = ""
1453
+ if safe_qn:
1454
+ check_blocks += (
1455
+ f'<div style="background:rgba(0,0,0,0.2); border-radius:8px; padding:12px; margin-bottom:8px;">'
1456
+ f'<div style="font-size:9px; color:#4A5568; margin-bottom:5px; text-transform:uppercase; letter-spacing:1.5px;">πŸ“Š μ •λŸ‰ 점검</div>'
1457
+ f'<div style="font-size:13px; color:#8B98B4; line-height:1.7;">{safe_qn}</div>'
1458
+ f'</div>'
1459
+ )
1460
+ if safe_ql:
1461
+ check_blocks += (
1462
+ f'<div style="background:rgba(0,0,0,0.2); border-radius:8px; padding:12px; margin-bottom:8px;">'
1463
+ f'<div style="font-size:9px; color:#8B98B4; margin-bottom:5px; text-transform:uppercase; letter-spacing:1.5px;">πŸ’‘ μ •μ„± 점검</div>'
1464
+ f'<div style="font-size:13px; color:#8B98B4; line-height:1.7;">{safe_ql}</div>'
1465
+ f'</div>'
1466
+ )
1467
+ # μ •λŸ‰/μ •μ„± μ—†μœΌλ©΄ κΈ°μ‘΄ current_status κ·ΈλŒ€λ‘œ (ꡬ버전 μΊμ‹œ ν˜Έν™˜)
1468
+ if not check_blocks:
1469
+ check_blocks = f'<div style="font-size:14px; color:#8B98B4; line-height:1.8;">{safe_curr}</div>'
1470
+ else:
1471
+ check_blocks += (
1472
+ f'<div style="background:rgba(0,0,0,0.15); border-radius:8px; padding:10px 12px; margin-top:4px;">'
1473
+ f'<div style="font-size:9px; color:#4A5568; margin-bottom:4px; text-transform:uppercase; letter-spacing:1.5px;">βš–οΈ μ’…ν•© νŒμ •</div>'
1474
+ f'<div style="font-size:13px; color:#EEF2F7; line-height:1.7; font-weight:500;">{safe_curr}</div>'
1475
+ f'</div>'
1476
+ )
1477
+
1478
+ st.markdown(
1479
+ f'<div style="background:{verdict_bg}; border:1px solid {verdict_color}33; '
1480
+ f'border-radius:12px; padding:20px; margin-bottom:14px;">'
1481
+ f'<div style="display:flex; align-items:center; gap:10px; margin-bottom:14px;">'
1482
+ f'<div class="analysis-header" style="margin-bottom:0;">1μˆœμœ„ Β· 맀수 ν…Œμ œ μœ νš¨μ„±</div>'
1483
+ f'<span style="font-size:13px; font-weight:900; color:{verdict_color}; '
1484
+ f'background:{verdict_bg}; border:1px solid {verdict_color}55; '
1485
+ f'padding:3px 12px; border-radius:20px;">{verdict}</span>'
1486
+ f'</div>'
1487
+ f'<div style="background:rgba(0,0,0,0.2); border-radius:8px; padding:12px; margin-bottom:10px;">'
1488
+ f'<div style="font-size:10px; color:#4A5568; margin-bottom:4px; text-transform:uppercase; letter-spacing:1px;">맀수 λ‹Ήμ‹œ κ·Όκ±°</div>'
1489
+ f'<div style="font-size:13px; color:#8B98B4;">{orig}</div>'
1490
+ f'</div>'
1491
+ f'{check_blocks}'
1492
+ f'</div>',
1493
+ unsafe_allow_html=True
1494
+ )
1495
 
1496
  # 2μˆœμœ„: ν˜„μž¬ μ•‘μ…˜
1497
  action_analysis = rpt.get("action_analysis", "")
 
1684
  # 4μˆœμœ„: 집쀑도 κ²½κ³ 
1685
  conc = rpt.get("concentration_warning", {})
1686
  if isinstance(conc, dict):
1687
+ tech_w = conc.get("tech_weight_pct", 0)
1688
+ warn_m = conc.get("warning_message", "")
1689
+ gvt = conc.get("growth_vs_turnaround", "")
1690
+ qn_conc = conc.get("quantitative_concentration", "")
1691
+ ql_conc = conc.get("qualitative_concentration", "")
1692
  tech_color = "#E53E3E" if tech_w >= 70 else ("#EAB308" if tech_w >= 50 else "#4ADE80")
1693
+
1694
+ conc_detail = ""
1695
+ if qn_conc:
1696
+ safe_qn = qn_conc.replace("\n","<br>")
1697
+ conc_detail += (
1698
+ f'<div style="background:rgba(0,0,0,0.2); border-radius:8px; padding:10px 12px; margin-bottom:8px;">'
1699
+ f'<div style="font-size:9px; color:#4A5568; margin-bottom:5px; text-transform:uppercase; letter-spacing:1.5px;">πŸ“Š μ •λŸ‰ 집쀑도</div>'
1700
+ f'<div style="font-size:13px; color:#8B98B4; line-height:1.7;">{safe_qn}</div>'
1701
+ f'</div>'
1702
+ )
1703
+ if ql_conc:
1704
+ safe_ql = ql_conc.replace("\n","<br>")
1705
+ conc_detail += (
1706
+ f'<div style="background:rgba(0,0,0,0.2); border-radius:8px; padding:10px 12px; margin-bottom:8px;">'
1707
+ f'<div style="font-size:9px; color:#8B98B4; margin-bottom:5px; text-transform:uppercase; letter-spacing:1.5px;">πŸ’‘ μ •μ„± 집쀑도 (ν…Œλ§ˆ 쀑볡)</div>'
1708
+ f'<div style="font-size:13px; color:#8B98B4; line-height:1.7;">{safe_ql}</div>'
1709
+ f'</div>'
1710
+ )
1711
+ if not conc_detail and warn_m:
1712
+ conc_detail = f'<div style="font-size:13px; color:#8B98B4; margin-bottom:8px;">{warn_m}</div>'
1713
+
1714
  st.markdown(
1715
  f'<div style="background:#0F1623; border:1px solid rgba(255,255,255,0.07); '
1716
  f'border-radius:10px; padding:16px; margin-bottom:14px;">'
 
1723
  f'<div style="background:rgba(255,255,255,0.04); border-radius:6px; height:8px; flex:1;">'
1724
  f'<div style="background:{tech_color}; width:{min(tech_w,100)}%; height:8px; border-radius:6px;"></div>'
1725
  f'</div></div>'
1726
+ f'{conc_detail}'
1727
+ f'{"<div style='background:#080C14;border-radius:6px;padding:8px 12px;font-size:12px;color:#8B98B4;'><b style='color:#4A5568;'>μ„±μž₯μ£Ό vs ν„΄μ–΄λΌμš΄λ“œ Β· </b>" + gvt + "</div>" if gvt else ""}'
1728
  f'</div>',
1729
  unsafe_allow_html=True
1730
  )
 
2474
  holding_days = f"{(datetime.now() - bd).days}일"
2475
  except: pass
2476
 
2477
+ # ── A. 맀수 κ·Όκ±° 없을 λ•Œ μž…λ ₯ μœ λ„ (뢄석은 계속 μ§„ν–‰) ──────
2478
+ buy_reason_pre = str(row.get('맀수근거', '') or '').strip()
2479
+ if not buy_reason_pre and not st.session_state.get(f"reason_skip_{ukey}", False):
2480
+ st.markdown(
2481
+ '<div style="background:rgba(201,168,76,0.06); border:1px solid rgba(201,168,76,0.25); '
2482
+ 'border-radius:10px; padding:16px 18px; margin-bottom:14px;">'
2483
+ '<div style="font-size:11px; font-weight:700; color:#C9A84C; letter-spacing:1.5px; '
2484
+ 'text-transform:uppercase; margin-bottom:8px;">✏️ 맀수 근거 미기둝</div>'
2485
+ '<div style="font-size:13px; color:#8B98B4; line-height:1.8; margin-bottom:12px;">'
2486
+ '맀수 λ‹Ήμ‹œ 생각을 적어두면 <b style="color:#EEF2F7;">ν…Œμ œ μœ νš¨μ„±</b>을 μ •ν™•ν•˜κ²Œ νŒλ‹¨ν•  수 μžˆμ–΄μš”.<br>'
2487
+ 'μ§€κΈˆ μž…λ ₯ν•˜μ§€ μ•Šμ•„λ„ 뢄석은 λ°”λ‘œ μ§„ν–‰λ˜μ§€λ§Œ, 기둝이 μ—†μœΌλ©΄ "μ™œ μƒ€λŠ”κ°€" 비ꡐ가 λΉ μ§‘λ‹ˆλ‹€.'
2488
+ '</div>'
2489
+ '</div>',
2490
+ unsafe_allow_html=True
2491
+ )
2492
+ reason_col1, reason_col2 = st.columns([0.75, 0.25], vertical_alignment="bottom")
2493
+ with reason_col1:
2494
+ inline_reason = st.text_input(
2495
+ "맀수 κ·Όκ±° (선택)",
2496
+ placeholder="예: AI 수주 λͺ¨λ©˜ν…€ / MA50 μ§€μ§€ 확인 / 저평가 ꡬ간 λΆ„ν• λ§€μˆ˜",
2497
+ key=f"inline_reason_{ukey}"
2498
+ )
2499
+ with reason_col2:
2500
+ if st.button("μ €μž₯ ν›„ 뢄석", key=f"save_reason_{ukey}", type="primary", use_container_width=True):
2501
+ if inline_reason.strip():
2502
+ idx_r = st.session_state.df[st.session_state.df['티컀'] == dt].index[0]
2503
+ st.session_state.df.at[idx_r, '맀수근거'] = inline_reason.strip()
2504
+ save_assets()
2505
+ st.session_state[f"reason_skip_{ukey}"] = True
2506
+ st.rerun()
2507
+ if st.button("κ·Όκ±° 없이 λ°”λ‘œ 뢄석", key=f"skip_reason_{ukey}", use_container_width=False):
2508
+ st.session_state[f"reason_skip_{ukey}"] = True
2509
+ st.rerun()
2510
+ st.stop()
2511
+
2512
  if needs:
2513
  with st.spinner(f"{n} 보유 μ’…λͺ© 진단 쀑..."):
2514
  fin_ctx, has_rich = get_rich_financial_context(dt)