benjamin5607 commited on
Commit
34faf8a
ยท
verified ยท
1 Parent(s): 528fc1b

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +91 -93
streamlit_app.py CHANGED
@@ -1,12 +1,11 @@
1
  import streamlit as st
2
  import yfinance as yf
3
- import FinanceDataReader as fdr
4
  import pandas as pd
5
  import requests
6
  import plotly.graph_objects as go
7
  from huggingface_hub import InferenceClient
8
 
9
- # 1. ํŽ˜์ด์ง€ ์„ค์ • (Wide ๋ชจ๋“œ & ๋‹คํฌ ํ…Œ๋งˆ ๊ฐ์„ฑ)
10
  st.set_page_config(
11
  page_title="Pocket Quant Pro",
12
  page_icon="๐Ÿ“ˆ",
@@ -14,20 +13,12 @@ st.set_page_config(
14
  initial_sidebar_state="expanded"
15
  )
16
 
17
- # --- [์Šคํƒ€์ผ๋ง] CSS๋กœ ์•ฝ๊ฐ„์˜ ํ™”์žฅ (๋ฉ”ํŠธ๋ฆญ ์นด๋“œ ์Šคํƒ€์ผ) ---
18
  st.markdown("""
19
  <style>
20
- [data-testid="stMetricValue"] {
21
- font-size: 24px;
22
- }
23
- div[data-testid="stStatusWidget"] div button {
24
- display: none;
25
- }
26
- .st-emotion-cache-1r6slb0 {
27
- border: 1px solid #333;
28
- border-radius: 10px;
29
- padding: 15px;
30
- }
31
  </style>
32
  """, unsafe_allow_html=True)
33
 
@@ -38,31 +29,56 @@ else:
38
  st.error("๐Ÿšจ ์„ค์ • ์˜ค๋ฅ˜: Secrets์— 'HF_TOKEN'์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
39
  st.stop()
40
 
41
- # --- ๋ฐ์ดํ„ฐ & ์กฑ๋ณด ---
42
- GLOBAL_TICKER_MAP = {
43
- "TSMC": "2330.TW", "MEDIATEK": "2454.TW", "FOXCONN": "2317.TW",
44
- "ALIBABA": "9988.HK", "TENCENT": "0700.HK", "BYD": "1211.HK",
45
- "RELIANCE": "RELIANCE.NS", "TCS": "TCS.NS", "INFOSYS": "INFY.NS",
46
- "DBS": "D05.SI", "SINGTEL": "Z74.SI", "SEA": "SE",
47
- "TOYOTA": "7203.T", "SONY": "6758.T", "SOFTBANK": "9984.T", "NINTENDO": "7974.T",
48
- "TESLA": "TSLA", "APPLE": "AAPL", "NVDA": "NVDA", "MSFT": "MSFT",
49
- "SAMSUNG": "005930.KS", "HYNIX": "000660.KS", "NAVER": "035420.KS"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  }
51
 
 
52
  MARKET_SAMPLES = {
53
  "๐Ÿ‡บ๐Ÿ‡ธ ๋ฏธ๊ตญ (USA)": ["AAPL", "NVDA", "TSLA", "AMZN", "MSFT", "GOOGL", "AMD"],
54
- "๐Ÿ‡ฐ๐Ÿ‡ท ํ•œ๊ตญ (Korea)": ["005930.KS", "000660.KS", "035420.KS", "005380.KS", "051910.KS"],
55
- "๐Ÿ‡ฏ๐Ÿ‡ต ์ผ๋ณธ (Japan)": ["7203.T", "6758.T", "9984.T", "8035.T", "6861.T"],
56
  "๐Ÿ‡จ๐Ÿ‡ณ ์ค‘๊ตญ/ํ™์ฝฉ": ["9988.HK", "0700.HK", "3690.HK", "1211.HK", "1810.HK"],
57
  "๐Ÿ‡น๐Ÿ‡ผ ๋Œ€๋งŒ (Taiwan)": ["2330.TW", "2454.TW", "2317.TW", "2308.TW"],
58
  "๐Ÿ‡ฎ๐Ÿ‡ณ ์ธ๋„ (India)": ["RELIANCE.NS", "TCS.NS", "HDFCBANK.NS", "INFY.NS"],
59
  "๐Ÿ‡ป๐Ÿ‡ณ ๋ฒ ํŠธ๋‚จ/์•„์„ธ์•ˆ": ["VIC", "VHM", "BBCA.JK", "D05.SI", "1155.KL"]
60
  }
61
 
62
- # --- ํ—ฌํผ ํ•จ์ˆ˜๋“ค ---
 
 
 
 
 
63
  def get_ticker_from_ai(name):
64
  try:
65
- prompt = f"Find Yahoo Finance ticker for '{name}'. Return ONLY ticker (e.g. 7203.T). No text."
66
  messages = [{"role": "user", "content": prompt}]
67
  response = client.chat.completions.create(
68
  model="Qwen/Qwen2.5-72B-Instruct", messages=messages, max_tokens=20
@@ -102,77 +118,60 @@ def parse_stream(stream):
102
  if hasattr(delta, 'content') and delta.content:
103
  yield delta.content.replace("```markdown", "").replace("```", "")
104
 
105
- # --- [์ฐจํŠธ ๊ทธ๋ฆฌ๊ธฐ] ์บ”๋“ค ์ฐจํŠธ ---
106
  def plot_candle_chart(hist, title):
107
  fig = go.Figure(data=[go.Candlestick(
108
- x=hist.index,
109
- open=hist['Open'], high=hist['High'],
110
- low=hist['Low'], close=hist['Close'],
111
- name="Price"
112
  )])
113
  fig.update_layout(
114
- title=dict(text=f"{title} Trend", x=0),
115
- height=350, margin=dict(l=10, r=10, t=40, b=10),
116
- xaxis_rangeslider_visible=False,
117
- template="plotly_dark",
118
- paper_bgcolor='rgba(0,0,0,0)',
119
- plot_bgcolor='rgba(0,0,0,0)'
120
  )
121
  return fig
122
 
123
- # --- [์ฐจํŠธ ๊ทธ๋ฆฌ๊ธฐ] ๋ง‰๋Œ€ ์ฐจํŠธ (์ปฌ๋Ÿฌ ์—๋Ÿฌ ์ˆ˜์ •๋จ) ---
124
  def plot_bar_chart(df):
125
- # ์ƒ์Šน(Green), ํ•˜๋ฝ(Red) ์ƒ‰์ƒ ์ง€์ •
126
  colors = ['#00FF00' if x > 0 else '#FF0000' for x in df['Change(%)']]
127
-
128
  fig = go.Figure(go.Bar(
129
- x=df.index,
130
  y=df['Change(%)'],
131
- marker_color=colors, # ์—ฌ๊ธฐ๊ฐ€ ์ˆ˜์ •๋œ ํฌ์ธํŠธ!
132
  text=df['Change(%)'].apply(lambda x: f"{x:.2f}%"),
133
  textposition='auto'
134
  ))
135
  fig.update_layout(
136
- title="Market Heatmap (Change %)",
137
- height=300, margin=dict(l=10, r=10, t=40, b=10),
138
- template="plotly_dark",
139
- paper_bgcolor='rgba(0,0,0,0)',
140
- plot_bgcolor='rgba(0,0,0,0)'
141
  )
142
  return fig
143
 
144
  # ==============================================================================
145
- # ๐Ÿ“ฑ ์‚ฌ์ด๋“œ๋ฐ” (Navigation)
146
  # ==============================================================================
147
  with st.sidebar:
148
  st.header("๐ŸŒ Pocket Quant Pro")
149
- st.write("AI Powered Global Investment")
150
  st.divider()
151
  menu = st.radio("MENU", ["๐Ÿ” ์ข…๋ชฉ ๋ถ„์„ (AI Analysis)", "๐Ÿ“ก ์‹œ์žฅ ์Šค์บ๋„ˆ (Market Watch)"], index=0)
152
  st.divider()
153
- st.caption("Powered by Qwen-2.5-72B")
154
 
155
  # ==============================================================================
156
  # 1. ์ข…๋ชฉ ๋ถ„์„ ๋ชจ๋“œ
157
  # ==============================================================================
158
  if "์ข…๋ชฉ ๋ถ„์„" in menu:
159
  st.subheader("๐Ÿ” AI Investment Analyst")
160
-
161
  c1, c2 = st.columns([3, 1])
162
- with c1:
163
- user_input = st.text_input("Ticker or Name", "TSMC", label_visibility="collapsed", placeholder="์ข…๋ชฉ๋ช…")
164
- with c2:
165
- analyze_btn = st.button("Analysis", use_container_width=True)
166
 
167
  if analyze_btn:
168
- with st.status("๐Ÿš€ Processing Market Data...", expanded=True) as status:
169
  ticker = search_ticker(user_input)
170
-
171
  if ticker:
172
  try:
173
  stock = yf.Ticker(ticker)
174
  hist = stock.history(period="3mo")
175
-
176
  if not hist.empty:
177
  curr = hist['Close'].iloc[-1]
178
  prev = hist['Close'].iloc[-2]
@@ -180,14 +179,13 @@ if "์ข…๋ชฉ ๋ถ„์„" in menu:
180
  vol = hist['Volume'].iloc[-1]
181
 
182
  info = stock.info
183
- if ".KS" in ticker or ".KQ" in ticker:
184
- info.update(get_naver_stock_info(ticker))
185
-
186
  per = info.get('trailingPE', 'N/A')
187
  pbr = info.get('priceToBook', 'N/A')
188
  currency = info.get('currency', '')
189
 
190
- status.update(label="โœ… Rendering...", state="complete", expanded=False)
191
 
192
  st.divider()
193
  m1, m2, m3, m4 = st.columns(4)
@@ -200,39 +198,26 @@ if "์ข…๋ชฉ ๋ถ„์„" in menu:
200
 
201
  st.subheader(f"๐Ÿง  AI Insight: {user_input}")
202
  prompt = f"""
203
- [ROLE] Global Analyst.
204
- [TASK] Analyze {user_input} ({ticker}).
205
  [DATA] Price:{curr}, Chg:{change_pct:.2f}%, PER:{per}, PBR:{pbr}
206
- [LANG] Reply in user's language.
207
- [OUT] Markdown. No Code blocks. 1.Summary 2.Valuation 3.Strategy
208
  """
209
  messages = [{"role": "user", "content": prompt}]
210
- stream = client.chat.completions.create(
211
- model="Qwen/Qwen2.5-72B-Instruct", messages=messages, stream=True
212
- )
213
- with st.container(border=True):
214
- st.write_stream(parse_stream(stream))
215
- else:
216
- status.update(label="โŒ No Data", state="error")
217
- st.error("๋ฐ์ดํ„ฐ ์—†์Œ")
218
- except Exception as e:
219
- status.update(label="โŒ Error", state="error")
220
- st.error(f"Error: {e}")
221
- else:
222
- status.update(label="โŒ Not Found", state="error")
223
- st.error("์ข…๋ชฉ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
224
 
225
  # ==============================================================================
226
- # 2. ์‹œ์žฅ ์Šค์บ๋„ˆ ๋ชจ๋“œ
227
  # ==============================================================================
228
  elif "์‹œ์žฅ ์Šค์บ๋„ˆ" in menu:
229
  st.subheader("๐Ÿ“ก Global Market Watch")
230
 
231
  col_sel, col_btn = st.columns([3, 1])
232
- with col_sel:
233
- target_market = st.selectbox("Select Market", list(MARKET_SAMPLES.keys()), label_visibility="collapsed")
234
- with col_btn:
235
- scan_trigger = st.button("Scan Market", use_container_width=True)
236
 
237
  if scan_trigger:
238
  tickers = MARKET_SAMPLES[target_market]
@@ -244,20 +229,33 @@ elif "์‹œ์žฅ ์Šค์บ๋„ˆ" in menu:
244
  prev = data.iloc[-2]
245
  pct = ((last - prev)/prev)*100
246
 
 
247
  df = pd.DataFrame({'Price': last, 'Change(%)': pct})
 
 
 
 
 
 
248
  df = df.dropna().sort_values('Change(%)', ascending=False)
249
 
250
- # [์ˆ˜์ •๋จ] Plotly Bar Chart ์‚ฌ์šฉ (์—๋Ÿฌ ํ•ด๊ฒฐ)
251
  st.plotly_chart(plot_bar_chart(df), use_container_width=True)
252
 
253
  c1, c2 = st.columns(2)
254
  with c1:
255
  st.success("๐Ÿš€ Top Gainers")
256
- st.dataframe(df.head(3).style.format({"Price": "{:,.2f}", "Change(%)": "{:,.2f}%"}), use_container_width=True)
 
 
 
 
257
  with c2:
258
  st.error("๐Ÿ“‰ Top Losers")
259
- st.dataframe(df.tail(3).sort_values('Change(%)').style.format({"Price": "{:,.2f}", "Change(%)": "{:,.2f}%"}), use_container_width=True)
260
- else:
261
- st.warning("No data received.")
262
- except Exception as e:
263
- st.error(f"Scan failed: {e}")
 
 
 
1
  import streamlit as st
2
  import yfinance as yf
 
3
  import pandas as pd
4
  import requests
5
  import plotly.graph_objects as go
6
  from huggingface_hub import InferenceClient
7
 
8
+ # 1. ํŽ˜์ด์ง€ ์„ค์ •
9
  st.set_page_config(
10
  page_title="Pocket Quant Pro",
11
  page_icon="๐Ÿ“ˆ",
 
13
  initial_sidebar_state="expanded"
14
  )
15
 
16
+ # --- ์Šคํƒ€์ผ๋ง ---
17
  st.markdown("""
18
  <style>
19
+ [data-testid="stMetricValue"] { font-size: 24px; }
20
+ div[data-testid="stStatusWidget"] div button { display: none; }
21
+ .st-emotion-cache-1r6slb0 { border: 1px solid #333; border-radius: 10px; padding: 15px; }
 
 
 
 
 
 
 
 
22
  </style>
23
  """, unsafe_allow_html=True)
24
 
 
29
  st.error("๐Ÿšจ ์„ค์ • ์˜ค๋ฅ˜: Secrets์— 'HF_TOKEN'์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
30
  st.stop()
31
 
32
+ # --- [์—…๋ฐ์ดํŠธ] ํ‹ฐ์ปค -> ๊ธฐ์—…๋ช… ๋งคํ•‘ ๋ฆฌ์ŠคํŠธ (์ด๋ฆ„ํ‘œ) ---
33
+ TICKER_NAMES = {
34
+ # ๐Ÿ‡บ๐Ÿ‡ธ ๋ฏธ๊ตญ
35
+ "AAPL": "Apple", "NVDA": "NVIDIA", "TSLA": "Tesla", "AMZN": "Amazon",
36
+ "MSFT": "Microsoft", "GOOGL": "Google", "AMD": "AMD", "META": "Meta",
37
+
38
+ # ๐Ÿ‡ฐ๐Ÿ‡ท ํ•œ๊ตญ
39
+ "005930.KS": "์‚ผ์„ฑ์ „์ž", "000660.KS": "SKํ•˜์ด๋‹‰์Šค", "035420.KS": "NAVER",
40
+ "005380.KS": "ํ˜„๋Œ€์ฐจ", "051910.KS": "LGํ™”ํ•™", "000270.KS": "๊ธฐ์•„", "035720.KS": "์นด์นด์˜ค",
41
+
42
+ # ๐Ÿ‡ฏ๐Ÿ‡ต ์ผ๋ณธ
43
+ "7203.T": "Toyota", "6758.T": "Sony", "9984.T": "SoftBank",
44
+ "8035.T": "Tokyo Electron", "6861.T": "Keyence", "7974.T": "Nintendo",
45
+
46
+ # ๐Ÿ‡จ๐Ÿ‡ณ ์ค‘๊ตญ/ํ™์ฝฉ
47
+ "9988.HK": "Alibaba", "0700.HK": "Tencent", "3690.HK": "Meituan",
48
+ "1211.HK": "BYD", "1810.HK": "Xiaomi",
49
+
50
+ # ๐Ÿ‡น๐Ÿ‡ผ ๋Œ€๋งŒ
51
+ "2330.TW": "TSMC", "2454.TW": "MediaTek", "2317.TW": "Foxconn", "2308.TW": "Delta Elec",
52
+
53
+ # ๐Ÿ‡ฎ๐Ÿ‡ณ ์ธ๋„
54
+ "RELIANCE.NS": "Reliance Ind", "TCS.NS": "TCS", "HDFCBANK.NS": "HDFC Bank",
55
+ "INFY.NS": "Infosys",
56
+
57
+ # ๐Ÿ‡ป๐Ÿ‡ณ ์•„์„ธ์•ˆ
58
+ "VIC": "Vingroup", "VHM": "Vinhomes", "BBCA.JK": "Bank Central Asia",
59
+ "D05.SI": "DBS Group", "1155.KL": "Maybank"
60
  }
61
 
62
+ # --- ๋ฐ์ดํ„ฐ ์ƒ˜ํ”Œ ๋ฆฌ์ŠคํŠธ ---
63
  MARKET_SAMPLES = {
64
  "๐Ÿ‡บ๐Ÿ‡ธ ๋ฏธ๊ตญ (USA)": ["AAPL", "NVDA", "TSLA", "AMZN", "MSFT", "GOOGL", "AMD"],
65
+ "๐Ÿ‡ฐ๐Ÿ‡ท ํ•œ๊ตญ (Korea)": ["005930.KS", "000660.KS", "035420.KS", "005380.KS", "051910.KS", "035720.KS"],
66
+ "๐Ÿ‡ฏ๐Ÿ‡ต ์ผ๋ณธ (Japan)": ["7203.T", "6758.T", "9984.T", "8035.T", "6861.T", "7974.T"],
67
  "๐Ÿ‡จ๐Ÿ‡ณ ์ค‘๊ตญ/ํ™์ฝฉ": ["9988.HK", "0700.HK", "3690.HK", "1211.HK", "1810.HK"],
68
  "๐Ÿ‡น๐Ÿ‡ผ ๋Œ€๋งŒ (Taiwan)": ["2330.TW", "2454.TW", "2317.TW", "2308.TW"],
69
  "๐Ÿ‡ฎ๐Ÿ‡ณ ์ธ๋„ (India)": ["RELIANCE.NS", "TCS.NS", "HDFCBANK.NS", "INFY.NS"],
70
  "๐Ÿ‡ป๐Ÿ‡ณ ๋ฒ ํŠธ๋‚จ/์•„์„ธ์•ˆ": ["VIC", "VHM", "BBCA.JK", "D05.SI", "1155.KL"]
71
  }
72
 
73
+ # --- ์กฑ๋ณด ๋ฐ ๊ฒ€์ƒ‰ ํ—ฌํผ ---
74
+ GLOBAL_TICKER_MAP = {
75
+ "TSMC": "2330.TW", "ALIBABA": "9988.HK", "RELIANCE": "RELIANCE.NS",
76
+ "TOYOTA": "7203.T", "SONY": "6758.T", "SAMSUNG": "005930.KS"
77
+ }
78
+
79
  def get_ticker_from_ai(name):
80
  try:
81
+ prompt = f"Find Yahoo Finance ticker for '{name}'. Return ONLY ticker. No text."
82
  messages = [{"role": "user", "content": prompt}]
83
  response = client.chat.completions.create(
84
  model="Qwen/Qwen2.5-72B-Instruct", messages=messages, max_tokens=20
 
118
  if hasattr(delta, 'content') and delta.content:
119
  yield delta.content.replace("```markdown", "").replace("```", "")
120
 
121
+ # --- ์ฐจํŠธ ๊ทธ๋ฆฌ๊ธฐ ํ•จ์ˆ˜๋“ค ---
122
  def plot_candle_chart(hist, title):
123
  fig = go.Figure(data=[go.Candlestick(
124
+ x=hist.index, open=hist['Open'], high=hist['High'], low=hist['Low'], close=hist['Close'], name="Price"
 
 
 
125
  )])
126
  fig.update_layout(
127
+ title=dict(text=f"{title} Trend", x=0), height=350, margin=dict(l=10, r=10, t=40, b=10),
128
+ xaxis_rangeslider_visible=False, template="plotly_dark",
129
+ paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)'
 
 
 
130
  )
131
  return fig
132
 
 
133
  def plot_bar_chart(df):
 
134
  colors = ['#00FF00' if x > 0 else '#FF0000' for x in df['Change(%)']]
 
135
  fig = go.Figure(go.Bar(
136
+ x=df['Name'], # X์ถ•์„ ๊ธฐ์—…๋ช…์œผ๋กœ ํ‘œ์‹œ!
137
  y=df['Change(%)'],
138
+ marker_color=colors,
139
  text=df['Change(%)'].apply(lambda x: f"{x:.2f}%"),
140
  textposition='auto'
141
  ))
142
  fig.update_layout(
143
+ title="Market Heatmap (Change %)", height=300, margin=dict(l=10, r=10, t=40, b=10),
144
+ template="plotly_dark", paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)'
 
 
 
145
  )
146
  return fig
147
 
148
  # ==============================================================================
149
+ # ์‚ฌ์ด๋“œ๋ฐ”
150
  # ==============================================================================
151
  with st.sidebar:
152
  st.header("๐ŸŒ Pocket Quant Pro")
153
+ st.write("AI Global Investment")
154
  st.divider()
155
  menu = st.radio("MENU", ["๐Ÿ” ์ข…๋ชฉ ๋ถ„์„ (AI Analysis)", "๐Ÿ“ก ์‹œ์žฅ ์Šค์บ๋„ˆ (Market Watch)"], index=0)
156
  st.divider()
157
+ st.caption("Data: Yahoo & Naver")
158
 
159
  # ==============================================================================
160
  # 1. ์ข…๋ชฉ ๋ถ„์„ ๋ชจ๋“œ
161
  # ==============================================================================
162
  if "์ข…๋ชฉ ๋ถ„์„" in menu:
163
  st.subheader("๐Ÿ” AI Investment Analyst")
 
164
  c1, c2 = st.columns([3, 1])
165
+ with c1: user_input = st.text_input("Ticker", "TSMC", label_visibility="collapsed", placeholder="์ข…๋ชฉ๋ช…")
166
+ with c2: analyze_btn = st.button("Go", use_container_width=True)
 
 
167
 
168
  if analyze_btn:
169
+ with st.status("๐Ÿš€ Analyzing...", expanded=True) as status:
170
  ticker = search_ticker(user_input)
 
171
  if ticker:
172
  try:
173
  stock = yf.Ticker(ticker)
174
  hist = stock.history(period="3mo")
 
175
  if not hist.empty:
176
  curr = hist['Close'].iloc[-1]
177
  prev = hist['Close'].iloc[-2]
 
179
  vol = hist['Volume'].iloc[-1]
180
 
181
  info = stock.info
182
+ if ".KS" in ticker or ".KQ" in ticker: info.update(get_naver_stock_info(ticker))
183
+
 
184
  per = info.get('trailingPE', 'N/A')
185
  pbr = info.get('priceToBook', 'N/A')
186
  currency = info.get('currency', '')
187
 
188
+ status.update(label="โœ… Ready!", state="complete", expanded=False)
189
 
190
  st.divider()
191
  m1, m2, m3, m4 = st.columns(4)
 
198
 
199
  st.subheader(f"๐Ÿง  AI Insight: {user_input}")
200
  prompt = f"""
201
+ [ROLE] Analyst. [TASK] Analyze {user_input} ({ticker}).
 
202
  [DATA] Price:{curr}, Chg:{change_pct:.2f}%, PER:{per}, PBR:{pbr}
203
+ [LANG] User's language. [OUT] Markdown. No Code. Summary/Valuation/Strategy.
 
204
  """
205
  messages = [{"role": "user", "content": prompt}]
206
+ stream = client.chat.completions.create(model="Qwen/Qwen2.5-72B-Instruct", messages=messages, stream=True)
207
+ with st.container(border=True): st.write_stream(parse_stream(stream))
208
+ else: status.update(label="โŒ No Data", state="error"); st.error("No Data")
209
+ except Exception as e: status.update(label="โŒ Error", state="error"); st.error(f"Error: {e}")
210
+ else: status.update(label="โŒ Not Found", state="error"); st.error("Not Found")
 
 
 
 
 
 
 
 
 
211
 
212
  # ==============================================================================
213
+ # 2. ์‹œ์žฅ ์Šค์บ๋„ˆ ๋ชจ๋“œ (๊ธฐ์—…๋ช… ์ถ”๊ฐ€๋จ)
214
  # ==============================================================================
215
  elif "์‹œ์žฅ ์Šค์บ๋„ˆ" in menu:
216
  st.subheader("๐Ÿ“ก Global Market Watch")
217
 
218
  col_sel, col_btn = st.columns([3, 1])
219
+ with col_sel: target_market = st.selectbox("Market", list(MARKET_SAMPLES.keys()), label_visibility="collapsed")
220
+ with col_btn: scan_trigger = st.button("Scan", use_container_width=True)
 
 
221
 
222
  if scan_trigger:
223
  tickers = MARKET_SAMPLES[target_market]
 
229
  prev = data.iloc[-2]
230
  pct = ((last - prev)/prev)*100
231
 
232
+ # [์—…๋ฐ์ดํŠธ] ๊ธฐ์—…๋ช…(Name) ์ปฌ๋Ÿผ ์ถ”๊ฐ€
233
  df = pd.DataFrame({'Price': last, 'Change(%)': pct})
234
+
235
+ # ์ด๋ฆ„ํ‘œ ๋”•์…”๋„ˆ๋ฆฌ์—์„œ ์ด๋ฆ„ ์ฐพ์•„์˜ค๊ธฐ (์—†์œผ๋ฉด ๊ทธ๋ƒฅ ํ‹ฐ์ปค ์‚ฌ์šฉ)
236
+ df['Name'] = [TICKER_NAMES.get(x, x) for x in df.index]
237
+
238
+ # ์ปฌ๋Ÿผ ์ˆœ์„œ ์ •๋ฆฌ: ์ด๋ฆ„ | ๊ฐ€๊ฒฉ | ๋“ฑ๋ฝ๋ฅ 
239
+ df = df[['Name', 'Price', 'Change(%)']]
240
  df = df.dropna().sort_values('Change(%)', ascending=False)
241
 
242
+ # ์ฐจํŠธ ๊ทธ๋ฆฌ๊ธฐ (๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ X์ถ•์„ ์ด๋ฆ„์œผ๋กœ ์„ค์ •)
243
  st.plotly_chart(plot_bar_chart(df), use_container_width=True)
244
 
245
  c1, c2 = st.columns(2)
246
  with c1:
247
  st.success("๐Ÿš€ Top Gainers")
248
+ st.dataframe(
249
+ df.head(3).style.format({"Price": "{:,.2f}", "Change(%)": "{:,.2f}%"}),
250
+ use_container_width=True,
251
+ column_config={"Name": "๊ธฐ์—…๋ช…"} # ํ—ค๋” ์ด๋ฆ„ ์˜ˆ์˜๊ฒŒ
252
+ )
253
  with c2:
254
  st.error("๐Ÿ“‰ Top Losers")
255
+ st.dataframe(
256
+ df.tail(3).sort_values('Change(%)').style.format({"Price": "{:,.2f}", "Change(%)": "{:,.2f}%"}),
257
+ use_container_width=True,
258
+ column_config={"Name": "๊ธฐ์—…๋ช…"}
259
+ )
260
+ else: st.warning("No data received.")
261
+ except Exception as e: st.error(f"Scan failed: {e}")