Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ import yfinance as yf
|
|
| 17 |
# --------------------------
|
| 18 |
# CONFIG
|
| 19 |
# --------------------------
|
| 20 |
-
st.set_page_config(page_title="📰
|
| 21 |
API_KEY = "88bc396d4eab4be494a4b86ec842db47"
|
| 22 |
|
| 23 |
# --------------------------
|
|
@@ -149,12 +149,12 @@ def fetch_stock_price(symbol, start_date, end_date):
|
|
| 149 |
# MAIN APP
|
| 150 |
# --------------------------
|
| 151 |
def main():
|
| 152 |
-
st.title("📰
|
| 153 |
st.markdown("วิเคราะห์แนวโน้มอารมณ์ของข่าวย้อนหลัง 7 วัน พร้อมราคาหุ้น")
|
| 154 |
|
| 155 |
# Sidebar
|
| 156 |
with st.sidebar:
|
| 157 |
-
keyword = st.text_input("
|
| 158 |
analyze_btn = st.button("วิเคราะห์เลย")
|
| 159 |
|
| 160 |
if not analyze_btn:
|
|
@@ -247,16 +247,16 @@ def main():
|
|
| 247 |
# 4. (*** ใหม่ ***) คำนวณและตีความ Correlation
|
| 248 |
correlation = plot_data['price'].corr(plot_data['avg_sentiment'])
|
| 249 |
|
| 250 |
-
corr_text = "
|
| 251 |
-
corr_delta = f"
|
| 252 |
|
| 253 |
if pd.isna(correlation):
|
| 254 |
corr_text = "ไม่สามารถคำนวณได้"
|
| 255 |
corr_delta = "N/A"
|
| 256 |
elif correlation > 0.3:
|
| 257 |
-
corr_text = "
|
| 258 |
elif correlation < -0.3:
|
| 259 |
-
corr_text = "
|
| 260 |
|
| 261 |
# 5. เทรนโมเดล Prediction (ใช้ข้อมูลที่ Merge แล้ว)
|
| 262 |
plot_data["timestamp"] = (plot_data["date_day"] - plot_data["date_day"].min()).dt.days
|
|
@@ -276,7 +276,7 @@ def main():
|
|
| 276 |
|
| 277 |
# 6. (*** ใหม่ ***) แสดงผล Correlation Metric
|
| 278 |
st.metric(
|
| 279 |
-
label="
|
| 280 |
value=corr_text,
|
| 281 |
delta=corr_delta
|
| 282 |
)
|
|
|
|
| 17 |
# --------------------------
|
| 18 |
# CONFIG
|
| 19 |
# --------------------------
|
| 20 |
+
st.set_page_config(page_title="📰 News Sentiment Analysis for Young Investor", layout="wide")
|
| 21 |
API_KEY = "88bc396d4eab4be494a4b86ec842db47"
|
| 22 |
|
| 23 |
# --------------------------
|
|
|
|
| 149 |
# MAIN APP
|
| 150 |
# --------------------------
|
| 151 |
def main():
|
| 152 |
+
st.title("📰 News Sentiment Analysis for Young Investor")
|
| 153 |
st.markdown("วิเคราะห์แนวโน้มอารมณ์ของข่าวย้อนหลัง 7 วัน พร้อมราคาหุ้น")
|
| 154 |
|
| 155 |
# Sidebar
|
| 156 |
with st.sidebar:
|
| 157 |
+
keyword = st.text_input("ค้นหา Stock Symbol (เช่น AAPL, TSLA):", "")
|
| 158 |
analyze_btn = st.button("วิเคราะห์เลย")
|
| 159 |
|
| 160 |
if not analyze_btn:
|
|
|
|
| 247 |
# 4. (*** ใหม่ ***) คำนวณและตีความ Correlation
|
| 248 |
correlation = plot_data['price'].corr(plot_data['avg_sentiment'])
|
| 249 |
|
| 250 |
+
corr_text = "ไม่มีความสัมพันธ์กัน"
|
| 251 |
+
corr_delta = f"Correlation = {correlation:.2f}"
|
| 252 |
|
| 253 |
if pd.isna(correlation):
|
| 254 |
corr_text = "ไม่สามารถคำนวณได้"
|
| 255 |
corr_delta = "N/A"
|
| 256 |
elif correlation > 0.3:
|
| 257 |
+
corr_text = "มีความสัมพันธ์กันในทิศทางเดียวกัน"
|
| 258 |
elif correlation < -0.3:
|
| 259 |
+
corr_text = "มีความสัมพันธ์กันในทิศทางตรงข้าม"
|
| 260 |
|
| 261 |
# 5. เทรนโมเดล Prediction (ใช้ข้อมูลที่ Merge แล้ว)
|
| 262 |
plot_data["timestamp"] = (plot_data["date_day"] - plot_data["date_day"].min()).dt.days
|
|
|
|
| 276 |
|
| 277 |
# 6. (*** ใหม่ ***) แสดงผล Correlation Metric
|
| 278 |
st.metric(
|
| 279 |
+
label="วิเคราะห์ความสัมพันธ์ (Sentiment vs Price)",
|
| 280 |
value=corr_text,
|
| 281 |
delta=corr_delta
|
| 282 |
)
|