【发布时间】:2018-04-18 06:42:17
【问题描述】:
我尝试在 url('/hello') 上的 URL(/predict) 中呈现变量('predictions')。我是网络开发的初学者。如果有人知道,请帮忙。
app = Flask(__name__)
@app.route('/predict', methods=['POST'])
def apicall(responses = None):
test_json = request.get_json()
test = pd.read_json(test_json, orient='records')
query_df = pd.DataFrame(test)
clf = 'kmeans__model.pkl'
print("Loading the model...")
lin_reg_model = None
with open(clf,'rb') as f:
lin_reg_model = joblib.load(f)
# lin_reg_model = joblib.load('/home/q/new_project/models/kmeans_model.pkl')
print("The model has been loaded...doing predictions now...")
predictions = lin_reg_model.predict(test)
print(predictions)
prediction_series = list(pd.Series(predictions))
final_predictions = pd.DataFrame(list(zip(prediction_series)))
responses = jsonify(predictions=final_predictions.to_json(orient="records"))
responses.status_code = 200
return (responses)
@app.route('/hello')
def hello():
**What should be used here to render *predictions*?**
return 'Hello, World '
【问题讨论】:
-
hello url执行时是否要运行
apicall函数? -
是的,我也想在 hello url 中打印名为“predictions”的变量。是否可以在预测 url 中呈现此变量?
-
是什么阻止了您不通过烧瓶路由调用类似 apicall() 的函数。
-
是否可以在predict url中渲染这个变量?
-
我还是不明白。得到预测后,您想在模板中显示吗?
标签: machine-learning flask web-deployment