Compare commits

..

12 Commits
master ... docs

Author SHA1 Message Date
f1ea6d84dc . 2019-01-05 20:18:42 +00:00
f793d181a7 . 2019-01-05 20:18:35 +00:00
b8843f7a2c . 2019-01-05 20:18:27 +00:00
70b0088fc9 . 2019-01-05 20:18:21 +00:00
87bae82711 . 2019-01-05 20:18:14 +00:00
2c93b6fa9c . 2019-01-05 20:18:07 +00:00
69e362f02e . 2019-01-05 20:17:43 +00:00
df0754ff9d . 2019-01-05 20:17:35 +00:00
bb55dd8993 t2 2019-01-05 20:16:37 +00:00
24d62ffb79 . 2019-01-05 20:15:57 +00:00
ea24cf5195 . 2019-01-05 20:14:39 +00:00
ab10a501a8 Prześlij pliki do '' 2019-01-05 20:04:12 +00:00
19 changed files with 98 additions and 18 deletions

View File

@ -1,18 +0,0 @@
# Cat or Not - artifact repository
# First prototype
### Monday 15:30 group
## How to use this repository?
To send an artifact for evaluation, create a pull request with it. Accepted artifacts will be merged into repository.
In case of an artifact not passing a quality control, person responsible will be contacted with informations about necessary changes.
Documentation is located in the **docs** branch.
Application prototype is located in the **app** branch.
## 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/

BIN
Test Plan(2).pdf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

7
app/__init__.py Normal file
View File

@ -0,0 +1,7 @@
from flask import Flask
from config import Config
app = Flask(__name__)
app.config.from_object(Config)
from app import routes

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

20
app/cat_recognition.py Normal file
View File

@ -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

7
app/forms.py Normal file
View File

@ -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?')

10
app/picture_downloader.py Normal file
View File

@ -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

18
app/routes.py Normal file
View File

@ -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)

23
app/templates/base.html Normal file
View File

@ -0,0 +1,23 @@
<!doctype html>
<html>
<head>
{% if title %}
<title>{{ title }} | Cat or Not</title>
{% else %}
<title>Cat or Not</title>
{% endif %}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
{% block content %}{% endblock %}
</body>
</html>

13
app/templates/index.html Normal file
View File

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% block content %}
<h1>Check if the picture is cat or not!</h1>
<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.url.label }}<br>
{{ form.url }}
</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}