Skip to content

Instantly share code, notes, and snippets.

@Wesitos
Last active May 21, 2017 16:36
Show Gist options
  • Save Wesitos/9a03937162b7d1b5c09c0266ad454568 to your computer and use it in GitHub Desktop.
Save Wesitos/9a03937162b7d1b5c09c0266ad454568 to your computer and use it in GitHub Desktop.
Flask + Clarifai
<!DOCTYPE html>
<html>
<head>
<title>Titulo</title>
</head>
<body>
<form action="POST" target="/">
<input name="image" type="file" />
<input type="submit" />
</form>
</body>
</html>
from flask import Flask, render_template, request
import json
from base64 import b64encode
from clarifai.rest import ClarifaiApp
app = Flask(__name__, template_folder='.')
clarifai_app = ClarifaiApp('', '')
model = clarifai_app.models.get('general-v1.3')
@app.route('/', methods=['GET'])
def index():
return render_template('index.html')
@app.route("/", methods=['POST'])
def form():
if request.files.get('image'):
image = request.files['image'].stream.read()
b64_image = b64encode(image.encode())
return json.dumps(model.predict_by_bytes(b64_image))
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment