uvicorn works fine too
Browse files- app/main.py +36 -0
- requirements.txt +2 -1
app/main.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
|
| 4 |
+
from model import convert, predict
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# pydantic models
|
| 9 |
+
class StockIn(BaseModel):
|
| 10 |
+
ticker: str
|
| 11 |
+
days: int
|
| 12 |
+
|
| 13 |
+
class StockOut(StockIn):
|
| 14 |
+
forecast: dict
|
| 15 |
+
|
| 16 |
+
# routes
|
| 17 |
+
@app.get("/ping")
|
| 18 |
+
async def pong():
|
| 19 |
+
return {"ping": "pong!"}
|
| 20 |
+
|
| 21 |
+
@app.post("/predict", response_model=StockOut, status_code=200)
|
| 22 |
+
def get_prediction(payload: StockIn):
|
| 23 |
+
# import pdb ; pdb.set_trace()
|
| 24 |
+
ticker = payload.ticker
|
| 25 |
+
days = payload.days
|
| 26 |
+
|
| 27 |
+
prediction_list = predict(ticker, days)
|
| 28 |
+
|
| 29 |
+
if not prediction_list:
|
| 30 |
+
raise HTTPException(status_code=400, detail="Model not found.")
|
| 31 |
+
|
| 32 |
+
response_object = {
|
| 33 |
+
"ticker": ticker,
|
| 34 |
+
"days": days,
|
| 35 |
+
"forecast": convert(prediction_list)}
|
| 36 |
+
return response_object
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@ yfinance
|
|
| 5 |
matplotlib
|
| 6 |
kaleido
|
| 7 |
ipywidgets
|
| 8 |
-
neuralprophet
|
|
|
|
|
|
| 5 |
matplotlib
|
| 6 |
kaleido
|
| 7 |
ipywidgets
|
| 8 |
+
neuralprophet
|
| 9 |
+
uvicorn
|