KYTHY commited on
Commit
d2251f1
·
verified ·
1 Parent(s): 0a2425d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -6
app.py CHANGED
@@ -11,8 +11,6 @@ from sklearn.linear_model import LinearRegression
11
  import plotly.graph_objects as go
12
  from plotly.subplots import make_subplots
13
  import yfinance as yf
14
-
15
- # 🔥 เพิ่ม FinBERT
16
  import torch
17
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
18
 
@@ -312,19 +310,43 @@ def main():
312
  fig.add_trace(
313
  go.Scatter(
314
  x=future_dates, y=future_preds,
315
- name="Predicted Sentiment", mode="lines+markers", line=dict(dash="dash")
316
  ),
317
  row=1, col=1, secondary_y=True
318
  )
319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  # จำนวนข่าว
321
  for col in ["neutral", "negative", "positive"]:
322
  if col not in plot_data.columns:
323
  plot_data[col] = 0
324
 
325
- fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["neutral"], name="Neutral"), row=2, col=1)
326
- fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["negative"], name="Negative"), row=2, col=1)
327
- fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["positive"], name="Positive"), row=2, col=1)
 
 
 
 
328
 
329
  fig.update_layout(
330
  title=f"แนวโน้มอารมณ์ข่าว + ราคาหุ้น ({symbol})",
 
11
  import plotly.graph_objects as go
12
  from plotly.subplots import make_subplots
13
  import yfinance as yf
 
 
14
  import torch
15
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
16
 
 
310
  fig.add_trace(
311
  go.Scatter(
312
  x=future_dates, y=future_preds,
313
+ name="Predicted Sentiment", mode="lines+markers", line=dict(color="#02a1f7", dash="dash")
314
  ),
315
  row=1, col=1, secondary_y=True
316
  )
317
 
318
+ # ---------------------------------------------------------
319
+ # เส้นเชื่อม Actual -> Predicted
320
+ # ---------------------------------------------------------
321
+ last_actual_date = plot_data["date_day"].max()
322
+ last_actual_value = plot_data["avg_sentiment"].iloc[-1]
323
+ first_pred_date = future_dates[0]
324
+ first_pred_value = future_preds[0]
325
+
326
+ fig.add_trace(
327
+ go.Scatter(
328
+ x=[last_actual_date, first_pred_date],
329
+ y=[last_actual_value, first_pred_value],
330
+ mode="lines",
331
+ line=dict(color="purple", dash="dot"),
332
+ name="Connector Actual→Predicted"
333
+ ),
334
+ row=1, col=1, secondary_y=True
335
+ )
336
+
337
+
338
  # จำนวนข่าว
339
  for col in ["neutral", "negative", "positive"]:
340
  if col not in plot_data.columns:
341
  plot_data[col] = 0
342
 
343
+ fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["neutral"], name="Neutral",
344
+ marker_color='rgba(128, 128, 128, 0.7)'), row=2, col=1)
345
+ fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["negative"], name="Negative",
346
+ marker_color='rgba(255, 0, 0, 0.7)'), row=2, col=1)
347
+ fig.add_trace(go.Bar(x=plot_data["date_day"], y=plot_data["positive"], name="Positive",
348
+ marker_color='rgba(0, 128, 0, 0.7)'), row=2, col=1)
349
+
350
 
351
  fig.update_layout(
352
  title=f"แนวโน้มอารมณ์ข่าว + ราคาหุ้น ({symbol})",