How can I use a return value in a flask endpoint from another flask endpoint?
I am currently working with flask endpoints that are connected to my react frontend. My return value for val is "null". Return data is 100% correct as it appears in my server log.
How can I get the return value to be the value of data? I would appreciate a answer and also feedback on the overall code on how to make it better.
@app.route("/handyman", methods=["POST"])
def get_data():
if request.method == "POST":
data = request.form.get("url")
print(data)
return data
@app.route("/response")
def response():
try:
val = get_data()
return {
"sucess": val
}
except Exception as e:
print(f"exception", e)
Below is my entire code part for context. Here the error is:
TypeError: path should be path-like or io.BytesIO, not
@app.route("/handyman", methods=["POST"])
def get_data():
if request.method == "POST":
data = request.form.get("url")
print(data)
return data
def model():
val = get_data()
img = load_img(val, target_size=(150, 150 ))
img_array= img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
prediction = loaded_model.predict(img_array)[0]
print(prediction)
return prediction
def calculation():
prediction = model()
results = []
x1 = prediction[0]
x2 = prediction[1]
if x1 > 0.5:
result = "Händler"
results.append(result)
if x2 > 0.5:
result = "Baustelle"
results.append(result)
return results
@app.route("/response")
def response():
model()
result = calculation()
return {
"success": result[-1]
}