0

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)
4
  • How do you run the application? And did you export the entry point? Commented Feb 4, 2020 at 12:39
  • running it through the python file itself @J.G. Commented Feb 4, 2020 at 12:57
  • @User2382 did you try running it on 127.0.0.1 and connecting to 127.0.0.1:5000? Commented Feb 4, 2020 at 13:04
  • yes i did, i tried it on my mobile as well using IPv4 address @laundmo Commented Feb 4, 2020 at 13:08

1 Answer 1

2

You have defined a POST method here. If you access it on browser (like 127.0.0.1:5000), that would send a GET request.

Add a GET method for browser and use POST to access this method.

Sign up to request clarification or add additional context in comments.

2 Comments

isnt that only related to the data that will be parsed through and back the form but it cant even display the webpage now.
@User2382, tanujabhoyar is right. To view this in a browser you will need to define a route with a GET method, as that his what the browser sends in the HTTP request. Otherwise use Postman to create a test for the POST url path: postman.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.