KYTHY commited on
Commit
1e38a8a
·
verified ·
1 Parent(s): bc4213e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -35,7 +35,7 @@ tokenizer, model = load_finbert()
35
  # UTILITIES
36
  # --------------------------
37
  def analyze_text(text):
38
- """วิเคราะห์อารมณ์ข่าวด้วย FinBERT"""
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 วัน พร้อมราคาหุ้น (FinBERT)")
179
 
180
  # Sidebar
181
  with st.sidebar:
@@ -194,7 +194,7 @@ def main():
194
  return
195
 
196
  # วิเคราะห์ Sentiment
197
- st.info("กำลังวิเคราะห์อารมณ์ข่าวด้วย FinBERT...")
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
 
@@ -256,11 +256,11 @@ def main():
256
 
257
  corr_text = "ไม่มีความสัมพันธ์"
258
  if correlation > 0.5:
259
- corr_text = "มีความสัมพันธ์เชิงบวก"
260
  elif correlation < -0.5:
261
- corr_text = "มีความสัมพันธ์เชิงลบ"
262
 
263
- st.metric("ความสัมพันธ์ระหว่าง Sentiment Score กับราคาหุ้น", corr_text, f"{correlation:.2f}")
264
 
265
  # ---------------------------------------------------------
266
  # Forecast Sentiment
@@ -320,12 +320,16 @@ def main():
320
  if col not in plot_data.columns:
321
  plot_data[col] = 0
322
 
323
- fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["neutral"], name="Neutral"), row=2, col=1)
324
- fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["negative"], name="Negative"), row=2, col=1)
325
- fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["positive"], name="Positive"), row=2, col=1)
 
 
 
 
326
 
327
  fig.update_layout(
328
- title=f"แนวโน้มอารมณ์ข่าว + ราคาหุ้น ({symbol})",
329
  barmode="stack",
330
  height=650,
331
  hovermode="x unified",
 
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
 
 
256
 
257
  corr_text = "ไม่มีความสัมพันธ์"
258
  if correlation > 0.5:
259
+ corr_text = "มีความสัมพันธ์ในทิศทางเดียวกัน"
260
  elif correlation < -0.5:
261
+ corr_text = "มีความสัมพันธ์ในทิศทางตรงข้าม"
262
 
263
+ st.metric("วิเคราะห์ความสัมพันธ์ระหว่างอารมณ์ของข่าวกับราคาหุ้น", corr_text, f"{correlation:.2f}")
264
 
265
  # ---------------------------------------------------------
266
  # Forecast Sentiment
 
320
  if col not in plot_data.columns:
321
  plot_data[col] = 0
322
 
323
+ fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["neutral"], name="Neutral",
324
+ marker_color='rgba(128, 128, 128, 0.7)'), row=2, col=1)
325
+ fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["negative"], name="Negative",
326
+ marker_color='rgba(255, 0, 0, 0.7)'), row=2, col=1)
327
+ fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["positive"], name="Positive",
328
+ marker_color='rgba(0, 128, 0, 0.7)'), row=2, col=1)
329
+
330
 
331
  fig.update_layout(
332
+ title=f"แนวโน้มอารมณ์ของข่าว + ราคาหุ้น ({symbol})",
333
  barmode="stack",
334
  height=650,
335
  hovermode="x unified",