when I open the link 0.0.0.0:5000 in my browser I always get the message on the browser "This site can't be reached" the code seems to be working since I get this message on the console
Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
here is the code that I am using
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)
Today, there are two ways to expose your flask application to the internet. Deploy the web application in your office server which has a public IP address and domain name. Deploy the web application in the cloud such as AWS, MS Azure, GCP or web hosting companies like GoDaddy, SiteGround, A2Hosting etc.
To run the application, use the flask command or python -m flask . You need to tell the Flask where your application is with the --app option. As a shortcut, if the file is named app.py or wsgi.py , you don't have to use --app . See Command Line Interface for more details.
--host – the IP address of the web server to run your Flask application on. The default value is '127.0. 0.1'.
In general, this message
Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
informs you about the IP-address of your PC that will be listened to accept the request. It can be configured to listen to only one IP-address.
As it has been stated in the comments, if you are trying to reach your Web site from the same PC you develop on, you may use virtual (loop) address 127.0.0.1
. In case you want to check how your Web site will look on your other devices that are connected to the same network (i.e. tablet, phone, other PC whatever else), you need to type your PC's internal network IP address, and it differs from the loop. It may be e.g. 192.168.1.1 (you should check it on your NIC properties). And it may changes if you try to make something like live-demo to your friends.
So in order, to prevent you from checking each time, which one IP-address is valid for your PC right now, you can use 0.0.0.0
telling to your application 'listen for incoming requests from ALL the NICs, whatever IP-address they have'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With