Spaces:
Sleeping
Sleeping
| import os | |
| from fastapi import FastAPI, Request | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from dotenv import load_dotenv | |
| from portfolio_agent import portfolio_agent | |
| load_dotenv() | |
| app = FastAPI() | |
| # Allow frontend access | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| def root(): | |
| return {"status": "Portfolio Agent API is running"} | |
| async def chat(request: Request): | |
| data = await request.json() | |
| message = data.get("message", "") | |
| extra_context = os.getenv("extra_context") | |
| answer = portfolio_agent(message, extra_context) | |
| return {"reply": answer} | |