This is the code in my api.
from flask import Flask, request, redirect, url_for, flash, jsonify
import numpy as np
import joblib
app = Flask(__name__)
model = joblib.load('concrete-predicter.joblib')
@app.route('/', methods=['POST', 'GET'])
def feedModel():
print("backend started")
newdata = request.get_json('input')
print(newdata)
newDataArr = newdata['input'].split()
data = [
[float(newDataArr[0]), float(newDataArr[1]), float(newDataArr[2]), float(newDataArr[3]), float(newDataArr[4]),
float(newDataArr[5]), float(newDataArr[6]), float(newDataArr[7])]]
prediction = np.array2string(model.predict(data)[0])
print(prediction)
return jsonify(prediction)
if __name__ == '__main__':
app.run(port=5000, debug=True) # change to '0.0.0.0' your IPv4 address
#array['output']=prediction
Further this is the flutter code snippet
onPressed: () async {
var input =
"540.0 0.0 0.0 162.0 2.5 1040.0 676.0 28"; //Input string
final url = 'http://127.0.0.1:5000/';
final response = await http.post(
Uri.parse(url),
body: json.encode(
{
'input': input
},
),
);
},
In the server it shows "Bad Request Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)" this error.
However in the server I can get the value but its showing a error and not running to the next code line in dart.
In flutter project's shown error is given bellow.
Error: XMLHttpRequest error.
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 910:28 get current
packages/http/src/browser_client.dart 69:22 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1685:54 runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 159:18 handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 766:44 handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 795:13 _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 592:7 [_complete]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_pipe.dart 61:11 _cancelAndValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream.dart 1288:7 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14 _checkAndCall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39 dcall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/html/dart2js/html_dart2js.dart 37301:58 <fn>
at Object.createErrorWithStack (http://localhost:13265/dart_sdk.js:5080:12)
at Function._throw (http://localhost:13265/dart_sdk.js:20337:18)
at Function.throwWithStackTrace (http://localhost:13265/dart_sdk.js:20334:18)
at async._AsyncCallbackEntry.new.callback (http://localhost:13265/dart_sdk.js:40851:18)
at Object._microtaskLoop (http://localhost:13265/dart_sdk.js:40708:13)
at _startMicrotaskLoop (http://localhost:13265/dart_sdk.js:40714:13)
at http://localhost:13265/dart_sdk.js:36191:9