File size: 952 Bytes
e2b2661
 
0a6956c
e2b2661
0a6956c
 
 
e2b2661
 
0a6956c
 
 
 
e2b2661
0a6956c
 
 
 
 
e2b2661
0a6956c
 
 
e2b2661
0a6956c
 
 
 
 
e2b2661
0a6956c
 
e2b2661
0a6956c
e2b2661
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pandas as pd
import time
import requests

STREAM_FILE = "data/streaming/news_stream.csv"
API_URL = "http://localhost:8000/predict"
WAIT = 3  # seconds

def main():
    df = pd.read_csv(STREAM_FILE)

    print("📡 Starting stream...")
    print("-" * 50)

    while True:  # infinite streaming
        for _, row in df.iterrows():
            payload = {
                "sentence": row["text"]
            }

            try:
                r = requests.post(API_URL, json=payload, timeout=5)
                out = r.json()

                print(f"[{row['ticker']}]")
                print("Text      :", row["text"])
                print("Sentiment :", round(out["sentiment_score"], 3))
                print("Prediction:", round(out["predicted_return"], 4))
                print("-" * 50)

            except Exception as e:
                print("❌ API error:", e)

            time.sleep(WAIT)

if __name__ == "__main__":
    main()