简体   繁体   English

简单的 Flask 应用程序不起作用

[英]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.我有两个函数,来自 Web 应用程序用户的 get_data,然后是 infer_results,它打印图像类型的结果。

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/我开始遵循本教程: 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:但我得到的只是:

在此处输入图片说明

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.在旁注中,如果您能提供一些建议或建议,那就太好了:我应该如何构建我的应用程序:我只想用 Python 做。 But then, how should I design the UI: where user can put his data and upload it?但是,我应该如何设计 UI:用户可以在哪里放置他的数据并上传它? 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?有没有办法将我的所有代码(机器学习代码 + 用户输入/输出)打包到用户可以下载并在他的 PC 上运行的桌面应用程序中?

Instead of app.run(host="0.0.0.0", threaded=True)而不是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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM