【发布时间】:2020-11-18 19:59:51
【问题描述】:
我有一个项目,关于使用烧瓶在 React Native 中运行 ML 模型并将预测结果发送到 React Native 应用程序。
现在,我有这个代码:
@app.route('/')
def home():
return 'Hello, World!'
@app.route('/predict/<valueOne>,<valueTwo>')
def predict(valueOne, valueTwo):
prediction = model.predict([[valueOne, valueTwo]])
output = round(prediction[0], 2)
return 'Sales should be $ {}'.format(output)
if __name__ == "__main__":
app.run(debug=True)
如果我打开浏览器并运行http://127.0.0.1:5000/predict/2,3,它将如下所示:
我想在我的 react 本机控制台上打印值 (650.0)。我尝试使用fetch,但没有奏效。我该怎么做?
编辑: 这是我尝试使用 fetch 的方法:
console.log(fetch('http://127.0.0.1:5000/predict/2,3'))
输出是:
Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
}
【问题讨论】:
-
您是否在 fetch 中遇到任何错误?
-
@GuruparanGiritharan 嘿,嗯,我没有收到任何错误,但我不知道如何使用 fetch 获取值,我的一位朋友告诉我,您只能使用 fetch 来检索json 数组,对吗?
-
不,你可以检索任何东西检查这个答案在得到一个字符串stackoverflow.com/questions/45427386/…
-
@GuruparanGiritharan 是的,我刚刚试了一下,效果很好
标签: python react-native flask