8000 Final Project with ML pipeline integrated for Face Classification by code93 · Pull Request #9 · code93/trantor-bootcamp · GitHub
[go: up one dir, main page]

Skip to content

Final Project with ML pipeline integrated for Face Classification #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
flask_examples app
how the arrangements should be done, the blog posts iteration code, profile page, Create, read, update and delete of blogs and editing profile image also done.    NOTE: THERE IS AN ERROR IN MODELS OR RELATED TO FORMATION OF db FILE.
  • Loading branch information
code93 committed Jul 1, 2021
commit 42ec116daba8638b50059281e0f85895e9021a3b
4 changes: 4 additions & 0 deletions Project/flask_examples/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from puppycompanyblog import app

if __name__ == '__main__':
app.run(debug=True)
41 changes: 41 additions & 0 deletions Project/flask_examples/puppycompanyblog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# puppycompanyblog/__init__.py

import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager

app = Flask(__name__)

app.config['SECRET_KEY'] = 'mysecret'


##############################
### DATABASE SETUP ###########
##########################
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir,'data.sqlite')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
Migrate(app,db)


##########################
# LOGIN CONFIGS
login_manager = LoginManager()

login_manager.init_app(app)
login_manager.login_view = 'users.login'


##########################################

from puppycompanyblog.core.views import core
from puppycompanyblog.users.views import users
from puppycompanyblog.error_pages.handlers import error_pages

app.register_blueprint(core)
app.register_blueprint(users)
app.register_blueprint(error_pages)
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions Project/flask_examples/puppycompanyblog/core/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# core/views.py

from flask import render_template,request,Blueprint

core = Blueprint('core', __name__)

@core.route('/')
def index():
# MORE TO COME
return render_template('index.html')

@core.route('/info')
def info():
return render_template('info.html')

Empty file.
Binary file not shown.
12 changes: 12 additions & 0 deletions Project/flask_examples/puppycompanyblog/error_pages/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# handlers.py
from flask import Blueprint,render_template

error_pages = Blueprint('error_pages', __name__)

@error_pages.app_errorhandler(404)
def error_404(error):
return render_template('error_pages/404.html') , 404

@error_pages.app_errorhandler(403)
def error_403(error):
return render_template('error_pages/403.html'), 403
54 changes: 54 additions & 0 deletions Project/flask_examples/puppycompanyblog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#models.py
from datetime import datetime
from enum import unique
from puppycompanyblog.core.views import index
from puppycompanyblog import db, login_manager
from werkzeug.security import generate_password_hash,check_password_hash
from flask_login import UserMixin
from datetime import datetime

@login_manager.user_loader
def load_user(user_id):
return User.query.get(user_id)

class User(db.Model, UserMixin):

__tablename__ = 'users'

id = db.Column(db.Integer,primary_key=True)
profile_image = db.Column(db.String(64),nullable=False,default='default_profile.png')
email = db.Column(db.String(64), unique=True,index=True)
username = db.Column(db.String(64),unique=True,index=True)
password_hash = db.Column(db.String(128))

posts = db.relationship('BlogPost',backref='author',lazy=True)

def __init__(self,email,username,password):
self.email = email
self.username = username
self.password_hash = generate_password_hash(password)

def check_password(self,password):
return check_password_hash(self.password_hash,password)

def __repr__(self):
return f"Username {self.username}"

class BlogPost(db.Model):

users = db.relationship(User)

id = db.Column(db.Integer,primary_key=True)
user_id = db.Column(db.Integer,db.ForeignKey('users.id'), nullable = False)

date = db.Column(db.DateTime, nullable=False, default= datetime.utcnow)
title = db.Column(db.String(140),nullable=False)
text = db.Column(db.Text,nullable=False)

def __init__(self,title,text,user_id):
self.title = title
self.text = text
self.user_id = user_id

def __repr__(self):
return f"Post ID; {self.id} -- Date: {self.date} --- {self.title}"
46 changes: 46 additions & 0 deletions Project/flask_examples/puppycompanyblog/templates/account.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends "base.html" %}
{% block content %}
<div class="jumbotron">
<div align='center'>
<h1>Welcome to the page for {{current_user.username}}</h1>
<img align='center' src="{{url_for('static',filename='profile_pics/'+current_user.profile_image)}}">
</div>
</div>

<div class="container">
<form method="POST">

{{form.hidden_tag}}

<div class="form-group">
{{form.username.label(class='form-group')}}
{{form.username(class='form-control')}}
</div>



<div class="form-group">
{{form.email.label(class='form-group')}}
{{form.email(class='form-control')}}
</div>



<div class="form-group">
{{form.picture.label(class='form-group')}}
{{form.picture(class='form-control')}}
</div>



<div class="form-group">
{{form.submit(class='btn btn-primary')}}
</div>




</form>
</div>

{% endblock %}
48 changes: 48 additions & 0 deletions Project/flask_examples/puppycompanyblog/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<meta charset="UTF-8">

<title></title>
</head>
<body>
<ul class='nav'>
<li class='nav-link'>
<a href="{{url_for('core.index')}}">Home</a>
</li>
<li class='nav-link'>
<a href="{{url_for('core.info')}}">About</a>
</li>
{% if current_user.is_authenticated %}
<li class='nav-link'>
<a href="{{url_for('users.logout')}}">Log Out</a>
</li>
<li class='nav-link'>
<a href="{{url_for('users.account')}}">Account</a>
</li>
<li class='nav-link'>
<a href="#">Create Post</a>
</li>
{% else %}
<li class='nav-link'>
<a href="{{url_for('users.login')}}">Log In</a>
</li>
<li class='nav-link'>
<a href="{{url_for('users.register')}}">Register</a>
</li>
{% endif %}

</ul>
<div class='container'>
{% block content %}

{% endblock %}

</div>

</body>
</html>
F42D
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block content %}
<div class="jumbotron">
<h1>403 ACCESS FORBIDDEN!</h1>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block content %}
<div class="jumbotron">
<h1>404 PAGE NOT FOUND</h1>
</div>
{% endblock %}
6 changes: 6 additions & 0 deletions Project/flask_examples/puppycompanyblog/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block content %}
<div class="jumbotron">
<h1>Puppy Company Blog</h1>
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions Project/flask_examples/puppycompanyblog/templates/info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block content %}
<div class="jumbotron">
<h1>Info About Our Company</h1>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et recusandae ullam adipisci itaque ratione, laborum, ducimus dolorem officiis dolor vitae optio, deserunt harum id! Dolor officia illum maxime voluptatibus temporibus.</p>
</div>
{% endblock %}
9 changes: 9 additions & 0 deletions Project/flask_examples/puppycompanyblog/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block content %}
<form method="POST">
{{form.hidden_tag()}}
{{form.email.label}}{{form.email}}<br>
{{form.password.label}}{{form.password}}<br>
{{form.submit()}}
</form>
{% endblock %}
11 changes: 11 additions & 0 deletions Project/flask_examples/puppycompanyblog/templates/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block content %}
<form method="POST">
{{form.hidden_tag()}}
{{form.email.label}}{{form.email}}<br>
{{form.username.label}}{{form.username}}<br>
{{form.password.label}}{{form.password}}<br>
{{form.pass_confirm.label}}{{form.pass_confirm}}<br>
{{form.submit()}}
</form>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="jumbotron">
<div align='center'>
<h1>Welcome to the page for {{user.username}}</h1>
<img src="{{url_for('static',filename='profile_pics/'+user.profile_image)}}">
</div>
</div>


{% for post in blog_post.items %}
<h2><a href="{{url_for('blog_posts.blog_post',blog_post_id=post.id)}}">{{post.title}}</a></h2>
Written By: <a href="{{url_for('users.user_post',username=post.author.username)}}">{{post.author.username}}</a>
<p class="text-muted">Publised on: {{post.date.strftime("%Y-%m-%d")}}</p>
<br>
<p>{{post.text}}</p>
<br>
{% endfor %}
</div>

<nav aria-label="Page Navigation example">
<ul class="pagination justify-content-center">
{% for page_num in blog_posts.iter_pages(left_edge=1,right_edge=1,left_current=1,right_current=2) %}
{% if blog_posts.page == page_num %}
<li class='page_item disabled'>
<a class="page-link" href="{{url_for('users.user_posts',username=user.username,page=page_num)}}">{{page_num}}</a>
</li>
{% else %}
<li class='page_item'>
<a class="page-link" href="{{url_for('users.user_posts',username=user.username,page=page_num)}}">{{page_num}}</a>
</li>
{% endif %}
{% endfor %}
</ul>

</nav>




{% endblock %}
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
47 changes: 47 additions & 0 deletions Project/flask_examples/puppycompanyblog/users/forms.py
raise ValidationError('Your email has been registered already!')
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from flask.app import Flask
from flask_wtf import FlaskForm
from wtforms import StringField,PasswordField,SubmitField
from wtforms.validators import DataRequired, Email, EqualTo
from wtforms import ValidationError
from flask_wtf.file import FileField,FileAllowed

from flask_login import current_user
from puppycompanyblog.models import User

class LoginForm(FlaskForm):
email = StringField('Email',validators=[DataRequired(),Email()])
password = PasswordField('Password', validators=[DataRequired()])
submit = SubmitField('Log In')

class RegisterationForm(FlaskForm):
email = StringField('Email',validators=[DataRequired(),Email()])
username = StringField('UserName',validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired(), EqualTo('pass_confirm', message='Passwords must match')])
pass_confirm = PasswordField('Confirm Password', validators=[DataRequired()])
submit = SubmitField('Register')

def check_email(self,field):
if User.query.filter_by(email=field.data).first():
raise ValidationError('Your email has been registered already!')

def check_username(self,field):
if User.query.filter_by(username=field.data).first():
raise ValidationError('Your username has been registered already!')


class UpdateUserForm(FlaskForm):

email = StringField('Email',validators=[DataRequired(),Email()])
username = StringField('UserName',validators=[DataRequired()])
picture = FileField('Update profile Picture', validators=[FileAllowed(['jpg','png'])])
submit = SubmitField('Update')

def check_email(self,field):
if User.query.filter_by(email=field.data).first():

def check_username(self,field):
if User.query.filter_by(username=field.data).first():
raise ValidationError('Your username has been registered already!')


Loading
0