当我在浏览器中打开链接0.0.0.0:5000时,我总是在浏览器上收到消息“无法访问此网站”
自从我在控制台上收到这条消息后,代码似乎开始工作了Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
这是我正在使用的代码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)