mgbam commited on
Commit
ff9180e
·
verified ·
1 Parent(s): 67188f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -16,9 +16,14 @@ from fastapi.responses import HTMLResponse, StreamingResponse
16
  from fastapi.templating import Jinja2Templates
17
  from pydantic import BaseModel, constr
18
 
19
- # Import our modular, asynchronous service classes
20
- from app.price_fetcher import PriceFetcher
21
- from app.sentiment import SentimentAnalyzer
 
 
 
 
 
22
 
23
  # --- Pydantic Model for API Input Validation ---
24
 
@@ -68,6 +73,7 @@ async def run_periodic_updates(fetcher: PriceFetcher, interval_seconds: int):
68
  # --- FastAPI App Initialization ---
69
 
70
  app = FastAPI(title="CryptoSentinel AI", lifespan=lifespan)
 
71
  templates = Jinja2Templates(directory="app/templates")
72
 
73
  # --- API Endpoints ---
@@ -142,18 +148,14 @@ async def sentiment_stream(request: Request):
142
  </p>
143
  </div>
144
  """
145
- # ====================================================================
146
- # FIX APPLIED HERE
147
- # ====================================================================
148
- # 1. First, process the string to remove newlines. This avoids a
149
- # backslash in the f-string expression, fixing the SyntaxError.
150
  data_payload = html_fragment.replace('\n', '')
151
 
152
- # 2. Then, use the clean variable in the f-string to build the message.
153
  sse_message = f"event: sentiment_update\ndata: {data_payload}\n\n"
154
 
155
  yield sse_message
156
- # ====================================================================
157
 
158
  except (KeyError, TypeError):
159
  continue # Ignore malformed payloads
@@ -163,5 +165,6 @@ async def sentiment_stream(request: Request):
163
  # --- Main execution block for local development ---
164
  if __name__ == "__main__":
165
  import uvicorn
166
- # Correct run command for a file named 'app.py' in the root directory.
 
167
  uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
 
16
  from fastapi.templating import Jinja2Templates
17
  from pydantic import BaseModel, constr
18
 
19
+ # ====================================================================
20
+ # FIX APPLIED HERE
21
+ # ====================================================================
22
+ # Use relative imports because price_fetcher and sentiment are in the same 'app' directory.
23
+ from .price_fetcher import PriceFetcher
24
+ from .sentiment import SentimentAnalyzer
25
+ # ====================================================================
26
+
27
 
28
  # --- Pydantic Model for API Input Validation ---
29
 
 
73
  # --- FastAPI App Initialization ---
74
 
75
  app = FastAPI(title="CryptoSentinel AI", lifespan=lifespan)
76
+ # Assuming your project structure is /app/templates
77
  templates = Jinja2Templates(directory="app/templates")
78
 
79
  # --- API Endpoints ---
 
148
  </p>
149
  </div>
150
  """
151
+ # First, process the string to remove newlines. This avoids a
152
+ # backslash in the f-string expression, fixing the SyntaxError.
 
 
 
153
  data_payload = html_fragment.replace('\n', '')
154
 
155
+ # Then, use the clean variable in the f-string to build the message.
156
  sse_message = f"event: sentiment_update\ndata: {data_payload}\n\n"
157
 
158
  yield sse_message
 
159
 
160
  except (KeyError, TypeError):
161
  continue # Ignore malformed payloads
 
165
  # --- Main execution block for local development ---
166
  if __name__ == "__main__":
167
  import uvicorn
168
+ # This run command assumes you are running `python app.py` from within the /app directory
169
+ # or `python -m app.app` from the parent directory.
170
  uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)