I am deploying a machine learning model written in Python on a React JS project, using Flask.
However, it is required to display LIME or SHAP output. Has anyone got any ideas in how to render html or js output from Flask to React and then display it?
Below is my code that currently sends data as numbers, but not an image/html/js
@app.route('/api/v1', methods=['POST'])
def postTest():
formData = request.json
cols = ['TYPE','ORIG', 'DEST', 'DISTANCE']
flight = []
for a in cols:
flight.append(formData[a])
predic_son = formData['prediction']
shap_values = explainer.shap_values(np.array(flight).reshape(1,-1))
res = dict(zip(cols, shap_values[0]))
print(type(res))
return res
Code to take the response on react:
fetch('http://localhost:5000/api/v1', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: 'POST',
body: JSON.stringify(flight)
}).then(response => response.json()).then(response => console.log(response));