Spaces:
Runtime error

ditgun commited on
Commit
de64f67
ยท
verified ยท
1 Parent(s): a8f5a8c

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +87 -32
src/app.py CHANGED
@@ -1539,13 +1539,16 @@ def get_portfolio_prompt(target, owned=None, sector_summary=None, beta_info=None
1539
  "hedge_suggestion": "๋ฆฌ์Šคํฌ ํ—ค์ง€๋ฅผ ์œ„ํ•œ ๋‹ค๋ฅธ ์ข…๋ชฉ ์ถ”์ฒœ"
1540
  }},
1541
  "portfolio_outlook": {{
1542
- "optimistic": "๋‚™๊ด€ ์‹œ๋‚˜๋ฆฌ์˜ค 6๊ฐœ์›” ์ˆ˜์ต๋ฅ  (์˜ˆ: +28%)",
1543
- "base": "๊ธฐ๋ณธ ์‹œ๋‚˜๋ฆฌ์˜ค 6๊ฐœ์›” ์ˆ˜์ต๋ฅ  (์˜ˆ: +10%)",
1544
- "pessimistic": "๋น„๊ด€ ์‹œ๋‚˜๋ฆฌ์˜ค 6๊ฐœ์›” ์ˆ˜์ต๋ฅ  (์˜ˆ: -18%)",
1545
- "beta_note": "๋ฒ ํƒ€ ๊ธฐ๋ฐ˜ ๋ณ€๋™ํญ ํ•ด์„ 1๋ฌธ์žฅ",
1546
- "upside_note": "์• ๋„๋ฆฌ์ŠคํŠธ ์ปจ์„ผ์„œ์Šค ์—…์‚ฌ์ด๋“œ ํ•ด์„ 1๋ฌธ์žฅ",
1547
- "valuation_note": "ํ˜„์žฌ ๋ฐธ๋ฅ˜์—์ด์…˜(PERยท์„ฑ์žฅ๋ฅ ) ์ˆ˜์ค€ ํ‰๊ฐ€ 1๋ฌธ์žฅ",
1548
- "key_risk": "์ˆ˜์ต๋ฅ  ์‹คํ˜„์„ ๋ง‰์„ ํ•ต์‹ฌ ๋ฆฌ์Šคํฌ 1๊ฐ€์ง€"
 
 
 
1549
  }},
1550
  "concentration_warning": {{
1551
  "tech_weight_pct": 0,
@@ -1940,38 +1943,90 @@ def render_portfolio_report(rpt):
1940
  )
1941
 
1942
  # โ”€โ”€ AI ํ•ด์„ (์‹ค๋ฐ์ดํ„ฐ ๊ธฐ๋ฐ˜ ์‹œ๋‚˜๋ฆฌ์˜ค)
1943
- if isinstance(outlook, dict) and any(outlook.get(k) for k in ["optimistic","base","pessimistic"]):
1944
- opt = outlook.get("optimistic", "-")
1945
- base = outlook.get("base", "-")
1946
- pess = outlook.get("pessimistic", "-")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1947
  notes = [
1948
- ("⚡ ๋ฒ ํƒ€ ๊ธฐ๋ฐ˜", outlook.get("beta_note", "")),
1949
- ("๐ŸŽฏ ์ปจ์„ผ์„œ์Šค", outlook.get("upside_note", "")),
1950
- ("๐Ÿ“Š ๋ฐธ๋ฅ˜์—์ด์…˜", outlook.get("valuation_note", "")),
1951
- ("โš ๏ธ ํ•ต์‹ฌ ๋ฆฌ์Šคํฌ", outlook.get("key_risk", "")),
1952
  ]
1953
  notes_html = "".join([
1954
  f'<div style="border-left:2px solid rgba(255,255,255,0.08); padding:6px 12px; margin-bottom:8px;">'
1955
  f'<span style="font-size:9px; color:#444444; text-transform:uppercase; letter-spacing:1px;">{lbl}</span>'
1956
- f'<div style="font-size:12px; color:#666666; margin-top:3px; line-height:1.6;">{txt}</div></div>'
1957
  for lbl, txt in notes if txt
1958
  ])
1959
- st.markdown(
1960
- f'<div style="font-size:10px; font-weight:700; color:#444444; letter-spacing:2px; text-transform:uppercase; margin-bottom:8px;">๐Ÿค– AI ์‹œ๋‚˜๋ฆฌ์˜ค ํ•ด์„</div>'
1961
- f'<div style="display:grid; grid-template-columns:1fr 1fr 1fr; gap:10px; margin-bottom:14px;">'
1962
- f'<div style="background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.08); border-radius:10px; padding:16px; text-align:center;">'
1963
- f'<div style="font-size:9px; color:#AAAAAA; font-weight:700; margin-bottom:8px; text-transform:uppercase; letter-spacing:1px;">๐ŸŸข ๋‚™๊ด€</div>'
1964
- f'<div style="font-size:22px; font-weight:700; color:#AAAAAA; font-family:DM Mono,monospace;">{opt}</div></div>'
1965
- f'<div style="background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.08); border-radius:10px; padding:16px; text-align:center;">'
1966
- f'<div style="font-size:9px; color:#D8D8D8; font-weight:700; margin-bottom:8px; text-transform:uppercase; letter-spacing:1px;">โšช ๊ธฐ๋ณธ</div>'
1967
- f'<div style="font-size:22px; font-weight:700; color:#D8D8D8; font-family:DM Mono,monospace;">{base}</div></div>'
1968
- f'<div style="background:rgba(200,60,60,0.04); border:1px solid rgba(200,60,60,0.12); border-radius:10px; padding:16px; text-align:center;">'
1969
- f'<div style="font-size:9px; color:#E05C5C; font-weight:700; margin-bottom:8px; text-transform:uppercase; letter-spacing:1px;">๐Ÿ”ด ๋น„๊ด€</div>'
1970
- f'<div style="font-size:22px; font-weight:700; color:#E05C5C; font-family:DM Mono,monospace;">{pess}</div></div>'
1971
- f'</div>'
1972
- f'<div style="background:#0D0D0D; border:1px solid rgba(255,255,255,0.06); border-radius:10px; padding:14px;">{notes_html}</div>',
1973
- unsafe_allow_html=True
1974
- )
1975
  else:
1976
  st.markdown('<div style="text-align:center;padding:24px;color:#444444;font-size:13px;">์žฌ์ง„๋‹จ์„ ์‹คํ–‰ํ•˜๋ฉด ์‹ค๋ฐ์ดํ„ฐ ๊ธฐ๋ฐ˜ ์ „๋ง์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค</div>', unsafe_allow_html=True)
1977
 
 
1539
  "hedge_suggestion": "๋ฆฌ์Šคํฌ ํ—ค์ง€๋ฅผ ์œ„ํ•œ ๋‹ค๋ฅธ ์ข…๋ชฉ ์ถ”์ฒœ"
1540
  }},
1541
  "portfolio_outlook": {{
1542
+ "optimistic_pct": "+28%",
1543
+ "optimistic_desc": "ํฌํŠธํด๋ฆฌ์˜ค ์ „์ฒด ๊ด€์ ์˜ ๋‚™๊ด€ ์‹œ๋‚˜๋ฆฌ์˜ค - ๋ณด์œ  ์ข…๋ชฉ ์„ฑ์žฅ ๊ฐ€์†, ์„นํ„ฐ ํ…Œ๋งˆ ์ˆ˜ํ˜œ ๋“ฑ ๊ตฌ์ฒด์  ์กฐ๊ฑด 2๋ฌธ์žฅ",
1544
+ "base_pct": "+10%",
1545
+ "base_desc": "ํฌํŠธํด๋ฆฌ์˜ค ์ „์ฒด ๊ด€์ ์˜ ๊ธฐ๋ณธ ์‹œ๋‚˜๋ฆฌ์˜ค - ํ˜„์žฌ ์ปจ์„ผ์„œ์Šค ๊ธฐ๋ฐ˜ 2๋ฌธ์žฅ",
1546
+ "pessimistic_pct": "-18%",
1547
+ "pessimistic_desc": "ํฌํŠธํด๋ฆฌ์˜ค ์ „์ฒด ๊ด€์ ์˜ ๋น„๊ด€ ์‹œ๋‚˜๋ฆฌ์˜ค - ์„นํ„ฐ ์ง‘์ค‘ ๋ฆฌ์Šคํฌ, ๋งคํฌ๋กœ ์•…ํ™” ๋“ฑ ๊ตฌ์ฒด์  ์กฐ๊ฑด 2๋ฌธ์žฅ",
1548
+ "beta_note": "ํฌํŠธํด๋ฆฌ์˜ค ๊ฐ€์ค‘ํ‰๊ท  ๋ฒ ํƒ€ ๊ธฐ๋ฐ˜ ๋ณ€๋™ํญ ํ•ด์„ 1๋ฌธ์žฅ",
1549
+ "upside_note": "ํฌํŠธํด๋ฆฌ์˜ค ์• ๋„๋ฆฌ์ŠคํŠธ ์ปจ์„ผ์„œ์Šค ์—…์‚ฌ์ด๋“œ ํ•ด์„ 1๋ฌธ์žฅ",
1550
+ "valuation_note": "ํฌํŠธํด๋ฆฌ์˜ค ์ „์ฒด ๋ฐธ๋ฅ˜์—์ด์…˜(PERยท์„ฑ์žฅ๋ฅ ) ์ˆ˜์ค€ ํ‰๊ฐ€ 1๋ฌธ์žฅ",
1551
+ "key_risk": "ํฌํŠธํด๋ฆฌ์˜ค ์ˆ˜์ต๋ฅ  ์‹คํ˜„์„ ๋ง‰์„ ํ•ต์‹ฌ ๋ฆฌ์Šคํฌ 1๊ฐ€์ง€"
1552
  }},
1553
  "concentration_warning": {{
1554
  "tech_weight_pct": 0,
 
1943
  )
1944
 
1945
  # โ”€โ”€ AI ํ•ด์„ (์‹ค๋ฐ์ดํ„ฐ ๊ธฐ๋ฐ˜ ์‹œ๋‚˜๋ฆฌ์˜ค)
1946
+ if isinstance(outlook, dict) and any(outlook.get(k) for k in ["optimistic_pct","optimistic","base_pct","base","pessimistic_pct","pessimistic"]):
1947
+ import re as _re
1948
+
1949
+ def _bold_numbers(text):
1950
+ return _re.sub(
1951
+ r'([+\-]?\d[\d,]*\.?\d*\s*[%๋ฐฐ์›์–ต๋งŒ]+)',
1952
+ r'<strong style="color:#D8D8D8;">\1</strong>',
1953
+ str(text)
1954
+ )
1955
+
1956
+ scenarios = {
1957
+ "๋‚™๊ด€": {
1958
+ "pct": outlook.get("optimistic_pct") or outlook.get("optimistic", "-"),
1959
+ "desc": outlook.get("optimistic_desc") or outlook.get("optimistic", ""),
1960
+ "color": "#AAAAAA", "sel_border": "rgba(200,200,200,0.6)",
1961
+ "border": "rgba(255,255,255,0.10)", "bg": "rgba(255,255,255,0.05)", "icon": "๐ŸŸข",
1962
+ },
1963
+ "๊ธฐ๋ณธ": {
1964
+ "pct": outlook.get("base_pct") or outlook.get("base", "-"),
1965
+ "desc": outlook.get("base_desc") or outlook.get("base", ""),
1966
+ "color": "#D8D8D8", "sel_border": "rgba(220,220,220,0.6)",
1967
+ "border": "rgba(255,255,255,0.10)", "bg": "rgba(255,255,255,0.04)", "icon": "โšช",
1968
+ },
1969
+ "๋น„๊ด€": {
1970
+ "pct": outlook.get("pessimistic_pct") or outlook.get("pessimistic", "-"),
1971
+ "desc": outlook.get("pessimistic_desc") or outlook.get("pessimistic", ""),
1972
+ "color": "#E05C5C", "sel_border": "rgba(200,60,60,0.8)",
1973
+ "border": "rgba(200,60,60,0.25)", "bg": "rgba(200,60,60,0.05)", "icon": "๐Ÿ”ด",
1974
+ },
1975
+ }
1976
+
1977
+ p_key = f"p_outlook_tab_{id(rpt)}"
1978
+ if p_key not in st.session_state:
1979
+ st.session_state[p_key] = "๊ธฐ๋ณธ"
1980
+ p_selected = st.session_state[p_key]
1981
+
1982
+ st.markdown(
1983
+ '<div style="font-size:10px; font-weight:700; color:#444444; letter-spacing:2px; text-transform:uppercase; margin-bottom:8px;">๐Ÿค– AI ์‹œ๋‚˜๋ฆฌ์˜ค ํ•ด์„</div>',
1984
+ unsafe_allow_html=True
1985
+ )
1986
+
1987
+ cols = st.columns(3)
1988
+ for label, s in scenarios.items():
1989
+ col = cols[list(scenarios.keys()).index(label)]
1990
+ with col:
1991
+ if st.button(f"{s['icon']} {label}\n\n{s['pct']}", key=f"pol_{label}_{id(rpt)}", use_container_width=True):
1992
+ st.session_state[p_key] = label
1993
+ st.rerun()
1994
+
1995
+ sel = scenarios[p_selected]
1996
+ if sel["desc"] and len(str(sel["desc"])) > 5:
1997
+ st.markdown(
1998
+ f'<div style="margin-top:14px; padding:14px 16px; background:{sel["bg"]}; '
1999
+ f'border:1px solid {sel["border"]}; border-left:3px solid {sel["color"]}; '
2000
+ f'border-radius:8px; font-size:12px; color:#888888; line-height:1.9;">'
2001
+ f'{_bold_numbers(sel["desc"])}'
2002
+ f'</div>',
2003
+ unsafe_allow_html=True
2004
+ )
2005
+
2006
  notes = [
2007
+ ("&#9889; ๋ฒ ํƒ€ ๊ธฐ๋ฐ˜", outlook.get("beta_note", "")),
2008
+ ("๐ŸŽฏ ์ปจ์„ผ์„œ์Šค", outlook.get("upside_note", "")),
2009
+ ("๐Ÿ“Š ๋ฐธ๋ฅ˜์—์ด์…˜", outlook.get("valuation_note", "")),
 
2010
  ]
2011
  notes_html = "".join([
2012
  f'<div style="border-left:2px solid rgba(255,255,255,0.08); padding:6px 12px; margin-bottom:8px;">'
2013
  f'<span style="font-size:9px; color:#444444; text-transform:uppercase; letter-spacing:1px;">{lbl}</span>'
2014
+ f'<div style="font-size:11px; color:#555555; margin-top:3px; line-height:1.7;">{_bold_numbers(txt)}</div></div>'
2015
  for lbl, txt in notes if txt
2016
  ])
2017
+ key_risk = outlook.get("key_risk", "")
2018
+ risk_html = (
2019
+ f'<div style="font-size:11px; color:#777777; line-height:1.8; padding:10px 12px; '
2020
+ f'background:rgba(200,60,60,0.06); border-left:2px solid rgba(200,60,60,0.4); border-radius:4px;">'
2021
+ f'&#9888;&#65039; <strong>ํ•ต์‹ฌ ๋ฆฌ์Šคํฌ</strong> {key_risk}</div>'
2022
+ ) if key_risk else ""
2023
+ if notes_html or risk_html:
2024
+ st.markdown(
2025
+ f'<div style="background:#0D0D0D; border:1px solid rgba(255,255,255,0.06); border-radius:10px; padding:14px; margin-top:14px;">'
2026
+ f'{notes_html}{risk_html}'
2027
+ f'</div>',
2028
+ unsafe_allow_html=True
2029
+ )
 
 
 
2030
  else:
2031
  st.markdown('<div style="text-align:center;padding:24px;color:#444444;font-size:13px;">์žฌ์ง„๋‹จ์„ ์‹คํ–‰ํ•˜๋ฉด ์‹ค๋ฐ์ดํ„ฐ ๊ธฐ๋ฐ˜ ์ „๋ง์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค</div>', unsafe_allow_html=True)
2032