Skip to content

Instantly share code, notes, and snippets.



Last active Mar 23, 2020
What would you like to do?
from flask import Flask, render_template, url_for, request
import os
import requests
import cv2 as cv
app = Flask(__name__)
eas_url = "<EAS service URL>"
token = "EAS service token"
def index():
uploaded = False
return render_template("index.html", uploaded=uploaded)
@app.route('/', methods=["POST"])
def upload_and_predict():
uploaded = True
# Create directory to hold uploaded images
target = "static/img"
if not os.path.isdir(target):
# Save uploaded image
file = request.files.get("file")
filename = file.filename
filepath = "/".join([target, filename])
# Set the request data and parameters
img = cv.imread(filepath, 1)
_, img_encoded = cv.imencode('.jpg', img)
body = img_encoded.tostring()
headers = { 'Authorization' : token }
# Send request to EAS
response =, data=body, headers=headers)
return render_template("index.html", uploaded=uploaded, imgpath=filepath, prediction=response.text)
if __name__ == "__main__":, debug=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.