Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ tokenizer, model = load_finbert()
|
|
| 35 |
# UTILITIES
|
| 36 |
# --------------------------
|
| 37 |
def analyze_text(text):
|
| 38 |
-
"""
|
| 39 |
if not text or not text.strip():
|
| 40 |
return 0
|
| 41 |
|
|
@@ -175,7 +175,7 @@ def fetch_stock_price(symbol, start_date, end_date):
|
|
| 175 |
# --------------------------
|
| 176 |
def main():
|
| 177 |
st.title("📰 News Sentiment Analysis for Young Investor")
|
| 178 |
-
st.markdown("วิเคราะห์แนวโน้มอารมณ์ของข่าวย้อนหลัง 7 วัน พร้อมราคาหุ้น
|
| 179 |
|
| 180 |
# Sidebar
|
| 181 |
with st.sidebar:
|
|
@@ -194,7 +194,7 @@ def main():
|
|
| 194 |
return
|
| 195 |
|
| 196 |
# วิเคราะห์ Sentiment
|
| 197 |
-
st.info("
|
| 198 |
news_df["sentiment"] = news_df["text"].apply(analyze_text)
|
| 199 |
news_df["date"] = pd.to_datetime(news_df["date"])
|
| 200 |
|
|
@@ -217,7 +217,7 @@ def main():
|
|
| 217 |
# ---------------------------------------------------------
|
| 218 |
# เตรียมข้อมูลสำหรับกราฟ Sentiment & Price
|
| 219 |
# ---------------------------------------------------------
|
| 220 |
-
st.subheader("📈
|
| 221 |
|
| 222 |
news_df["date_day"] = pd.to_datetime(news_df["date"].dt.date)
|
| 223 |
|
|
@@ -255,12 +255,12 @@ def main():
|
|
| 255 |
correlation = plot_data['price'].corr(plot_data['avg_sentiment'])
|
| 256 |
|
| 257 |
corr_text = "ไม่มีความสัมพันธ์"
|
| 258 |
-
if correlation > 0.
|
| 259 |
-
corr_text = "
|
| 260 |
-
elif correlation < -0.
|
| 261 |
-
corr_text = "
|
| 262 |
|
| 263 |
-
st.metric("
|
| 264 |
|
| 265 |
# ---------------------------------------------------------
|
| 266 |
# Forecast Sentiment
|
|
@@ -328,7 +328,7 @@ def main():
|
|
| 328 |
x=[last_actual_date, first_pred_date],
|
| 329 |
y=[last_actual_value, first_pred_value],
|
| 330 |
mode="lines",
|
| 331 |
-
line=dict(color="
|
| 332 |
name="Connector Actual→Predicted"
|
| 333 |
),
|
| 334 |
row=1, col=1, secondary_y=True
|
|
|
|
| 35 |
# UTILITIES
|
| 36 |
# --------------------------
|
| 37 |
def analyze_text(text):
|
| 38 |
+
"""วิเคราะห์อารมณ์ของข่าว"""
|
| 39 |
if not text or not text.strip():
|
| 40 |
return 0
|
| 41 |
|
|
|
|
| 175 |
# --------------------------
|
| 176 |
def main():
|
| 177 |
st.title("📰 News Sentiment Analysis for Young Investor")
|
| 178 |
+
st.markdown("วิเคราะห์แนวโน้มอารมณ์ของข่าวย้อนหลัง 7 วัน พร้อมราคาหุ้น")
|
| 179 |
|
| 180 |
# Sidebar
|
| 181 |
with st.sidebar:
|
|
|
|
| 194 |
return
|
| 195 |
|
| 196 |
# วิเคราะห์ Sentiment
|
| 197 |
+
st.info("กำลังวิเคราะห์อารมณ์ของข่าว...")
|
| 198 |
news_df["sentiment"] = news_df["text"].apply(analyze_text)
|
| 199 |
news_df["date"] = pd.to_datetime(news_df["date"])
|
| 200 |
|
|
|
|
| 217 |
# ---------------------------------------------------------
|
| 218 |
# เตรียมข้อมูลสำหรับกราฟ Sentiment & Price
|
| 219 |
# ---------------------------------------------------------
|
| 220 |
+
st.subheader("📈 แนวโน้มอารมณ์ของข่าว & ราคาหุ้น")
|
| 221 |
|
| 222 |
news_df["date_day"] = pd.to_datetime(news_df["date"].dt.date)
|
| 223 |
|
|
|
|
| 255 |
correlation = plot_data['price'].corr(plot_data['avg_sentiment'])
|
| 256 |
|
| 257 |
corr_text = "ไม่มีความสัมพันธ์"
|
| 258 |
+
if correlation > 0.5:
|
| 259 |
+
corr_text = "มีความสัมพันธ์ในทิศทางเดียวกัน"
|
| 260 |
+
elif correlation < -0.5:
|
| 261 |
+
corr_text = "มีความสัมพันธ์ในทิศทางตรงกันข้าม"
|
| 262 |
|
| 263 |
+
st.metric("วิเคราะห์ความสัมพันธ์ระหว่างอารมณ์ของข่าวกับราคาหุ้น (Correlation)", corr_text, f"{correlation:.2f}")
|
| 264 |
|
| 265 |
# ---------------------------------------------------------
|
| 266 |
# Forecast Sentiment
|
|
|
|
| 328 |
x=[last_actual_date, first_pred_date],
|
| 329 |
y=[last_actual_value, first_pred_value],
|
| 330 |
mode="lines",
|
| 331 |
+
line=dict(color="#02a1f7", dash="dot"),
|
| 332 |
name="Connector Actual→Predicted"
|
| 333 |
),
|
| 334 |
row=1, col=1, secondary_y=True
|