Using RStudio Connect to deploy a flask API from python (rsconnect library). I really like the idea of adding swagger docs so using the flask-restx package, with guiding examples from RStudio docs (https://github.com/sol-eng/python-examples/blob/master/flask-restx/predict.py and https://docs.rstudio.com/connect/user/flask/#flask-restx).
Following this though, I'm getting this error upon deployment using rsconnect: " You are seeing this page because the Python API at this location does not provide a resource at the root ( GET / )". Has anyone ever encountered this before? If so, any troubleshooting advice?
I'm including my code below for added clarity:
## file is named: app.py
model = hub.load(model_folder)
def make_prediction(*, input_data) -> dict:
"""Make a prediction using saved tf model.
Args:
input_data: Array of model prediction inputs.
Returns:
Predictions for each input row
"""
data = tf.convert_to_tensor([input_data])
## loaded above
prediction = model(data).numpy()
return prediction.tolist()
app = Flask(__name__)
## added this because I kept getting CORS error-- hiding the actual server route here though
## this deviates from the RStudio example so maybe here?
app.config["SERVER_NAME"] = "base_url:port/content/#/"
# define the flask-restx boilerplate
api = Api(
app,
version="1.0.0",
title="Model API",
description="Predicts something"
)
# define the main subroute for requests
ns = api.namespace("predict", description="Predict something")
# define the API response
model_predict = api.model(
"Prediction",
{
"input": fields.String(required=True, description="text"),
"output": fields.Float(description = "Predicted")
},
)
# GET example that accepts a new data point as a query parameter in the URL path
# served at route + namespace, so at /predict/<user's text input>
@ns.route("/<string:text>")
@ns.param("input", "new text")
class Predict(Resource):
@ns.marshal_with(model_predict)
@ns.doc("get text ")
def get(self, input):
prediction = make_prediction(input_data=input)
return jsonify({'output': prediction, 'input': input})