I am trying to pull together a time-series predictor, that runs of a REST API.
The GET request should send 6 values, and then receive a series of predicted values back. However when I try to parse the values from the API, I realised that it is a JSON list, and I cant actually use the individual values. Is there a way to be able to get the individual values? Or is there a better JSON dtype that I should be using?
My code is:
num_days = np.arange(0, 14, 1) # the amount of days the model is required to predict for
app = FastAPI() # initiate the API
@app.get("/predict")
async def predict(data: List[str] = Query(...)): # input a list as a query from the GET request
print(data)
for i in num_days:
xpred = data[-6:]
print('xpred: %s' % xpred)
yhat = model.predict(np.asarray([xpred]))
print('Input: %s, Predicted: %.3f' % (xpred, yhat[0]))
data.append(int(yhat))
return(xpred)
The data param that the GET Call provides turns up as the following, rather than a normal list:
["'90','87','98','91','92','100'"]
I m new to JSON and APIs so any help would be hugely appreciated.