Rafael Rafael - 23 days ago 8
Python Question

Simple Flask Application Not Working

I trained a machine learning model which I wanted to deploy as an app. I learnt that flask is especially suited for this.

I have two functions, get_data from the user of the web app and then, infer_results which prints the results of image type.

I am trying to set up flask for the above use case. I started by following this tutorial: https://sourcedexter.com/python-rest-api-flask/

What I did:

In [71]: app = Flask(__name__)

In [72]: @app.route("/me", methods=["GET"])
...: def get_results():
...: return "Dummy Result"


And then,

In [73]: app.run(host="0.0.0.0", threaded=True)
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)


But all I get is:

enter image description here

I can't figure out what is going wrong? This is my main question.

On a sidenote, it would be really great if you could offer some advice or suggestion on : how should I go about building my app: I want to do in Python only. But then, how should I design the UI: where user can put his data and upload it? Is there a way to package all my code (the machine learning code + the user input/output) in a desktop application that user can download and run on his PC?

Answer Source

Instead of app.run(host="0.0.0.0", threaded=True)

Use:

app.run(host="localhost", threaded=True)

Or Execute the below script:

from flask import Flask, render_template

app = Flask(__name__)

# index
@app.route('/')
def index():
    return "Hello"

# /me    
@app.route("/me", methods=["GET"])
def get_results():
    return "Dummy Result"

if __name__ == "__main__":
    app.run()