Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- 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. ํ์ด์ง ์ค์
|
| 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 |
-
# ---
|
| 18 |
st.markdown("""
|
| 19 |
<style>
|
| 20 |
-
[data-testid="stMetricValue"] {
|
| 21 |
-
|
| 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 |
-
|
| 43 |
-
|
| 44 |
-
"
|
| 45 |
-
"
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
"
|
| 49 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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 |
-
|
| 116 |
-
|
| 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
|
| 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 |
-
|
| 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 |
-
#
|
| 146 |
# ==============================================================================
|
| 147 |
with st.sidebar:
|
| 148 |
st.header("๐ Pocket Quant Pro")
|
| 149 |
-
st.write("AI
|
| 150 |
st.divider()
|
| 151 |
menu = st.radio("MENU", ["๐ ์ข
๋ชฉ ๋ถ์ (AI Analysis)", "๐ก ์์ฅ ์ค์บ๋ (Market Watch)"], index=0)
|
| 152 |
st.divider()
|
| 153 |
-
st.caption("
|
| 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 |
-
|
| 164 |
-
with c2:
|
| 165 |
-
analyze_btn = st.button("Analysis", use_container_width=True)
|
| 166 |
|
| 167 |
if analyze_btn:
|
| 168 |
-
with st.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 |
-
|
| 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="โ
|
| 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]
|
| 204 |
-
[TASK] Analyze {user_input} ({ticker}).
|
| 205 |
[DATA] Price:{curr}, Chg:{change_pct:.2f}%, PER:{per}, PBR:{pbr}
|
| 206 |
-
[LANG]
|
| 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 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 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 |
-
|
| 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 |
-
#
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
with c2:
|
| 258 |
st.error("๐ Top Losers")
|
| 259 |
-
st.dataframe(
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
| 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}")
|