I have a python chatbot and I'm tryig to run the GUI of it by running it with flask, but I have tried various solutions for this post: Can't connect to Flask web service, connection refused.
In the end, none of the solutions managed to allow me to connect to the page. All the errors were displaying either 404 Not Found or Unable to Connect.
The code is provided from the sample codes of a medium post which serves as a tutorial for me to learn. Any helps or solutions to guide me on the right way would be appreciated.
The block that runs the flask code:
from flask import Flask, jsonify, request
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app)
@app.route("/katana-ml/api/v1.0/assistant", methods=['POST'])
def classify():
ERROR_THRESHOLD = 0.25
sentence = request.json['sentence']
# generate probabilities from the model
input_data = pd.DataFrame([bow(sentence, words)],
dtype=float, index=['input'])
results = model.predict([input_data])[0]
# filter out predictions below a threshold
results = [[i,r] for i,r in enumerate(results) if r>ERROR_THRESHOLD]
# sort by strength of probability
results.sort(key=lambda x: x[1], reverse=True)
return_list = []
for r in results:
return_list.append({"intent": classes[r[0]], "probability": str(r[1])})
# return tuple of intent and probability
response = jsonify(return_list)
return response
# running REST interface, port=5000 for direct test, port=5001 for deployment from PM2
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)