Spaces:
Sleeping
Sleeping
Update app/app.py
Browse files- app/app.py +8 -6
app/app.py
CHANGED
@@ -18,14 +18,10 @@ from fastapi import FastAPI, Request
|
|
18 |
from fastapi.responses import HTMLResponse, StreamingResponse
|
19 |
from fastapi.templating import Jinja2Templates
|
20 |
|
21 |
-
# ====================================================================
|
22 |
-
# FIX APPLIED HERE
|
23 |
-
# ====================================================================
|
24 |
# Use relative imports because these modules are in the same 'app' package.
|
25 |
from .price_fetcher import PriceFetcher
|
26 |
from .gemini_analyzer import GeminiAnalyzer
|
27 |
from newsapi import NewsApiClient
|
28 |
-
# ====================================================================
|
29 |
|
30 |
|
31 |
# --- Application Lifespan for Resource Management ---
|
@@ -42,7 +38,7 @@ async def lifespan(app: FastAPI):
|
|
42 |
app.state.gemini_analyzer = GeminiAnalyzer(client=client)
|
43 |
app.state.news_api = NewsApiClient(api_key=os.getenv("NEWS_API_KEY"))
|
44 |
|
45 |
-
# Create a queue for the real-time signal feed
|
46 |
app.state.signal_queue: asyncio.Queue = asyncio.Queue()
|
47 |
|
48 |
# Create cancellable background tasks for periodic updates.
|
@@ -135,7 +131,13 @@ async def serve_dashboard(request: Request):
|
|
135 |
@app.get("/api/signals/stream")
|
136 |
async def signal_stream(request: Request):
|
137 |
"""SSE stream for the automated Signal Stream."""
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
async def event_generator():
|
140 |
while True:
|
141 |
payload = await queue.get()
|
|
|
18 |
from fastapi.responses import HTMLResponse, StreamingResponse
|
19 |
from fastapi.templating import Jinja2Templates
|
20 |
|
|
|
|
|
|
|
21 |
# Use relative imports because these modules are in the same 'app' package.
|
22 |
from .price_fetcher import PriceFetcher
|
23 |
from .gemini_analyzer import GeminiAnalyzer
|
24 |
from newsapi import NewsApiClient
|
|
|
25 |
|
26 |
|
27 |
# --- Application Lifespan for Resource Management ---
|
|
|
38 |
app.state.gemini_analyzer = GeminiAnalyzer(client=client)
|
39 |
app.state.news_api = NewsApiClient(api_key=os.getenv("NEWS_API_KEY"))
|
40 |
|
41 |
+
# Create a queue for the real-time signal feed, attached to the app's state.
|
42 |
app.state.signal_queue: asyncio.Queue = asyncio.Queue()
|
43 |
|
44 |
# Create cancellable background tasks for periodic updates.
|
|
|
131 |
@app.get("/api/signals/stream")
|
132 |
async def signal_stream(request: Request):
|
133 |
"""SSE stream for the automated Signal Stream."""
|
134 |
+
# ====================================================================
|
135 |
+
# FIX APPLIED HERE
|
136 |
+
# ====================================================================
|
137 |
+
# Access the shared application state via `request.app.state`, not `request.state`.
|
138 |
+
queue: asyncio.Queue = request.app.state.signal_queue
|
139 |
+
# ====================================================================
|
140 |
+
|
141 |
async def event_generator():
|
142 |
while True:
|
143 |
payload = await queue.get()
|