Last active
May 21, 2017 16:36
-
-
Save Wesitos/9a03937162b7d1b5c09c0266ad454568 to your computer and use it in GitHub Desktop.
Flask + Clarifai
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Titulo</title> | |
</head> | |
<body> | |
<form action="POST" target="/"> | |
<input name="image" type="file" /> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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