diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..9df3bff --- /dev/null +++ b/Procfile @@ -0,0 +1,3 @@ +web: gunicorn cat_or_not +heroku ps:scale web=1 +export GOOGLE_APPLICATION_CREDENTIALS="authentication.json" diff --git a/README.md b/README.md index 6c9d621..56dd934 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Cat or Not - artifact repository +# First prototype ### Monday 15:30 group ## How to use this repository? @@ -8,3 +9,6 @@ In case of an artifact not passing a quality control, person responsible will be ## Version Control Document It is located in a [repository's wiki](https://git.wmi.amu.edu.pl/s434650/CatOrNot/wiki/Version+History+Document). It will be updated with each accepted artifact. + +## Heroku application +https://lit-wildwood-10245.herokuapp.com/ diff --git a/__pycache__/cat_or_not.cpython-36.pyc b/__pycache__/cat_or_not.cpython-36.pyc new file mode 100644 index 0000000..63f3e4d Binary files /dev/null and b/__pycache__/cat_or_not.cpython-36.pyc differ diff --git a/__pycache__/cat_recognition.cpython-36.pyc b/__pycache__/cat_recognition.cpython-36.pyc new file mode 100644 index 0000000..5f0382d Binary files /dev/null and b/__pycache__/cat_recognition.cpython-36.pyc differ diff --git a/__pycache__/config.cpython-36.pyc b/__pycache__/config.cpython-36.pyc new file mode 100644 index 0000000..442ed48 Binary files /dev/null and b/__pycache__/config.cpython-36.pyc differ diff --git a/__pycache__/forms.cpython-36.pyc b/__pycache__/forms.cpython-36.pyc new file mode 100644 index 0000000..18070b2 Binary files /dev/null and b/__pycache__/forms.cpython-36.pyc differ diff --git a/__pycache__/hello.cpython-36.pyc b/__pycache__/hello.cpython-36.pyc new file mode 100644 index 0000000..47f8c9f Binary files /dev/null and b/__pycache__/hello.cpython-36.pyc differ diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..f5b34f4 --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,7 @@ +from flask import Flask +from config import Config + +app = Flask(__name__) +app.config.from_object(Config) + +from app import routes diff --git a/app/__pycache__/__init__.cpython-36.pyc b/app/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..10c727a Binary files /dev/null and b/app/__pycache__/__init__.cpython-36.pyc differ diff --git a/app/__pycache__/cat_recognition.cpython-36.pyc b/app/__pycache__/cat_recognition.cpython-36.pyc new file mode 100644 index 0000000..9289b2a Binary files /dev/null and b/app/__pycache__/cat_recognition.cpython-36.pyc differ diff --git a/app/__pycache__/forms.cpython-36.pyc b/app/__pycache__/forms.cpython-36.pyc new file mode 100644 index 0000000..8e14a92 Binary files /dev/null and b/app/__pycache__/forms.cpython-36.pyc differ diff --git a/app/__pycache__/picture_downloader.cpython-36.pyc b/app/__pycache__/picture_downloader.cpython-36.pyc new file mode 100644 index 0000000..1fd1e52 Binary files /dev/null and b/app/__pycache__/picture_downloader.cpython-36.pyc differ diff --git a/app/__pycache__/routes.cpython-36.pyc b/app/__pycache__/routes.cpython-36.pyc new file mode 100644 index 0000000..32d5883 Binary files /dev/null and b/app/__pycache__/routes.cpython-36.pyc differ diff --git a/app/cat_recognition.py b/app/cat_recognition.py new file mode 100644 index 0000000..b65d418 --- /dev/null +++ b/app/cat_recognition.py @@ -0,0 +1,20 @@ +# Imports the Google Cloud client library +from google.cloud import vision +from google.cloud.vision import types + +def is_cat(content): + labels = fetch_data(content) + if labels[0].description == "cat": + return True + else: + return False + +def fetch_data(content): + # Instantiates a client + client = vision.ImageAnnotatorClient() + # Tell Google Vision that our content is of type Image + image = types.Image(content=content) + # Performs label detection on the image file + response = client.label_detection(image=image) + # Return array of labels + return response.label_annotations diff --git a/app/forms.py b/app/forms.py new file mode 100644 index 0000000..ab65d4c --- /dev/null +++ b/app/forms.py @@ -0,0 +1,7 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, PasswordField, BooleanField, SubmitField +from wtforms.validators import DataRequired + +class UploadForm(FlaskForm): + url = StringField('Link', validators=[DataRequired()]) + submit = SubmitField('Cat or not?') diff --git a/app/picture_downloader.py b/app/picture_downloader.py new file mode 100644 index 0000000..3304f35 --- /dev/null +++ b/app/picture_downloader.py @@ -0,0 +1,10 @@ +import requests + +def get_image_from_url(url): + f = open('pic.jpg','wb') + f.write(requests.get(url).content) + f.close() + f = open('pic.jpg','rb') + file = f.read() + f.close() + return file diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..feedcbd --- /dev/null +++ b/app/routes.py @@ -0,0 +1,18 @@ +from flask import Flask +from flask import render_template +from app.forms import UploadForm +from app import app +from app import cat_recognition as cat +from app import picture_downloader as downloader + +@app.route('/', methods=['GET', 'POST']) +def index(): + form = UploadForm() + if form.validate_on_submit(): + content = downloader.get_image_from_url(form.url.data) + if cat.is_cat(content): + return "Cat!" + else: + return "Not!" + + return render_template('index.html', form=form) diff --git a/app/templates/base.html b/app/templates/base.html new file mode 100644 index 0000000..519c49c --- /dev/null +++ b/app/templates/base.html @@ -0,0 +1,23 @@ + + +
+ {% if title %} +