forked from austinLorenzMccoy/financial-analysis-system
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
78 lines (56 loc) · 2.06 KB
/
Copy pathmain.py
File metadata and controls
78 lines (56 loc) · 2.06 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from datetime import datetime
from typing import List, Optional
from src.core.financial_analysis import FinancialAnalysisSystem
from src.utils.logger import logger
class AnalysisRequest(BaseModel):
ticker: str
start_date: str
end_date: Optional[str] = None
class AnalysisResponse(BaseModel):
ticker: str
market_insights: str
prediction_results: dict
visualization_paths: List[str]
app = FastAPI(
title="Financial Analysis API",
description="AI-powered financial analysis and prediction system",
version="0.1.0",
)
@app.post("/analyze", response_model=AnalysisResponse)
async def perform_financial_analysis(request: AnalysisRequest):
try:
# Log the incoming request
logger.info(f"Received analysis request for {request.ticker}")
# Use current date if end_date is not provided
end_date = request.end_date or datetime.now().strftime("%Y-%m-%d")
# Initialize analysis system
system = FinancialAnalysisSystem()
# Run analysis
result = system.run_analysis(
ticker=request.ticker, start_date=request.start_date, end_date=end_date
)
# Log successful analysis
logger.info(f"Completed analysis for {request.ticker}")
return AnalysisResponse(
ticker=request.ticker,
market_insights=result.get("market_insights", ""),
prediction_results=result.get("prediction_results", {}),
visualization_paths=result.get("visualization_paths", []),
)
except Exception as e:
# Log the error
logger.error(f"Analysis error: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
# Additional endpoints can be added here
@app.get("/")
async def root():
return {"message": "Financial Analysis API is running"}
@app.get("/health")
async def health_check():
return {"status": "healthy"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)