Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
f1ea6d84dc | |||
f793d181a7 | |||
b8843f7a2c | |||
70b0088fc9 | |||
87bae82711 | |||
2c93b6fa9c | |||
69e362f02e | |||
df0754ff9d | |||
bb55dd8993 | |||
24d62ffb79 | |||
ea24cf5195 | |||
ab10a501a8 |
18
README.md
18
README.md
@ -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
BIN
Test Plan(2).pdf
Normal file
Binary file not shown.
BIN
__pycache__/cat_or_not.cpython-36.pyc
Normal file
BIN
__pycache__/cat_or_not.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/cat_recognition.cpython-36.pyc
Normal file
BIN
__pycache__/cat_recognition.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/config.cpython-36.pyc
Normal file
BIN
__pycache__/config.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/forms.cpython-36.pyc
Normal file
BIN
__pycache__/forms.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/hello.cpython-36.pyc
Normal file
BIN
__pycache__/hello.cpython-36.pyc
Normal file
Binary file not shown.
7
app/__init__.py
Normal file
7
app/__init__.py
Normal 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
|
BIN
app/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/cat_recognition.cpython-36.pyc
Normal file
BIN
app/__pycache__/cat_recognition.cpython-36.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/forms.cpython-36.pyc
Normal file
BIN
app/__pycache__/forms.cpython-36.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/picture_downloader.cpython-36.pyc
Normal file
BIN
app/__pycache__/picture_downloader.cpython-36.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/routes.cpython-36.pyc
Normal file
BIN
app/__pycache__/routes.cpython-36.pyc
Normal file
Binary file not shown.
20
app/cat_recognition.py
Normal file
20
app/cat_recognition.py
Normal 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
7
app/forms.py
Normal 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
10
app/picture_downloader.py
Normal 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
18
app/routes.py
Normal 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
23
app/templates/base.html
Normal 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
13
app/templates/index.html
Normal 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 %}
|
Loading…
Reference in New Issue
Block a user