-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (26 loc) · 1.04 KB
/
main.py
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
from fastapi import FastAPI, Query
from pydantic import BaseModel
from market_analyser import MarketAnalyser
# Initialize FastAPI app
app = FastAPI()
# Initialize the MarketAnalyser instance
market_analyser = MarketAnalyser()
# Pydantic model for the API response
class MarketAnalysisResponse(BaseModel):
summary: str
@app.get("/analyze", response_model=MarketAnalysisResponse)
async def analyze_market(query: str = Query(..., description="Market query to search for news articles"),
limit: int = Query(20, description="Number of news articles to retrieve")):
"""
Analyze market trends based on the provided query.
"""
try:
# Call the analyze_market method of MarketAnalyser
summary = market_analyser.analyze_market(query=query, limit=limit)
return MarketAnalysisResponse(summary=summary)
except Exception as e:
return {"error": str(e)}
# Run this script using Uvicorn
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)