This site can’t be reached [flask, python]

10 浏览
0 Comments

This site can’t be reached [flask, python]

当我在浏览器中打开链接0.0.0.0:5000时,我总是在浏览器上收到"无法访问此站点"的消息。代码似乎运行正常,因为我在控制台上收到了这个消息:

Running on http://0.0.0.0:5000/ (按CTRL+C退出)

enter image description here

这是我正在使用的代码:

from flask import Flask, render_template, request
from scipy.misc import imsave, imread, imresize
import numpy as np
import keras.models
import re
import sys
import os
from load import *
sys.path.append(os.path.abspath('./model'))
app = Flask(__name__)
global model, graph
model, graph = init()
def convertImage(imData):
    imgstr = re.search(r'base64(.*'.imData).group(1)
    with open('output.png', 'wb') as output:
        output.write(imgstr.decode('base64'))
@app.route('/')
def index():
    return render_template('index.html')
@app.route('/predict', methods=['GET', 'POST'])
def predict():
    imData = request.get_data()
    convertImage(imData)
    x = imread('output.png', mode = 'L')
    x = np.invert(x)
    x = imresize(x, 48, 48)
    x = x.reshape(1,48,48,1)
    with graph.as_default():
        out = model.predict(x)
        response = np.array_str(np.argmax(out))
        return response
if __name__ == "__main__":
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

0