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
Prev Previous commit
Next Next commit
Final Project Done
Flask App is up and running.
  • Loading branch information
code93 committed Jul 2, 2021
commit 6d9027ff1055288087ea11757400560e3a3e7242
File renamed without changes.
File renamed without changes.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from puppycompanyblog import app
from companyblog import app

if __name__ == '__main__':
app.run(debug=True)
61 changes: 61 additions & 0 deletions Project/Website/Final_Project/companyblog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager


app = Flask(__name__)

#############################################################################
############ CONFIGURATIONS (CAN BE SEPARATE CONFIG.PY FILE) ###############
###########################################################################

# Remember you need to set your environment variables at the command line
# when you deploy this to a real website.
# export SECRET_KEY=mysecret
# set SECRET_KEY=mysecret
app.config['SECRET_KEY'] = 'mysecret'

#################################
### DATABASE SETUPS ############
###############################

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

# We can now pass in our app to the login manager
login_manager.init_app(app)

# Tell users what view to go to when they need to login.
login_manager.login_view = "users.login"


###########################
#### BLUEPRINT CONFIGS #######
#########################

# Import these at the top if you want
# We've imported them here for easy reference
from companyblog.core.views import core
from companyblog.users.views import users
from companyblog.blog_posts.views import blog_posts
from companyblog.error_pages.handlers import error_pages

# Register the apps
app.register_blueprint(users)
app.register_blueprint(blog_posts)
app.register_blueprint(core)
app.register_blueprint(error_pages)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions Project/Website/Final_Project/companyblog/blog_posts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, TextAreaField
from wtforms.validators import DataRequired


class BlogPostForm(FlaskForm):
# no empty titles or text possible
# we'll grab the date automatically from the Model later
title = StringField('Title', validators=[DataRequired()])
text = TextAreaField('Text', validators=[DataRequired()])
submit = SubmitField('BlogPost')
72 changes: 72 additions & 0 deletions Project/Website/Final_Project/companyblog/blog_posts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from os import abort
from flask import render_template,url_for,flash, redirect,request,Blueprint
from flask_login import current_user,login_required
from companyblog import db
from companyblog.models import BlogPost
from companyblog.blog_posts.forms import BlogPostForm

blog_posts = Blueprint('blog_posts',__name__)

@blog_posts.route('/create',methods=['GET','POST'])
@login_required
def create_post():
form = BlogPostForm()

if form.validate_on_submit():

blog_post = BlogPost(title=form.title.data,
text=form.text.data,
user_id=current_user.id
)
db.session.add(blog_post)
db.session.commit()
flash("Blog Post Created")
return redirect(url_for('core.index'))

return render_template('create_post.html',form=form)


# int: makes sure that the blog_post_id gets passed as in integer
# instead of a string so we can look it up later.
@blog_posts.route('/<int:blog_post_id>')
def blog_post(blog_post_id):
# grab the requested blog post by id number or return 404
blog_post = BlogPost.query.get_or_404(blog_post_id)
return render_template('blog_post.html',title=blog_post.title,
date=blog_post.date,post=blog_post
)

@blog_posts.route("/<int:blog_post_id>/update", methods=['GET', 'POST'])
@login_required
def update(blog_post_id):
blog_post = BlogPost.query.get_or_404(blog_post_id)
if blog_post.author != current_user:
# Forbidden, No Access
abort(403)

form = BlogPostForm()
if form.validate_on_submit():
blog_post.title = form.title.data
blog_post.text = form.text.data
db.session.commit()
flash('Post Updated')
return redirect(url_for('blog_posts.blog_post', blog_post_id=blog_post.id))
# Pass back the old blog post information so they can start again with
# the old text and title.
elif request.method == 'GET':
form.title.data = blog_post.title
form.text.data = blog_post.text
return render_template('create_post.html', title='Update',
form=form)


@blog_posts.route("/<int:blog_post_id>/delete", methods=['POST'])
@login_required
def delete_post(blog_post_id):
blog_post = BlogPost.query.get_or_404(blog_post_id)
if blog_post.author != current_user:
abort(403)
db.session.delete(blog_post)
db.session.commit()
flash('Post has been deleted')
return redirect(url_for('core.index'))
1 change: 1 addition & 0 deletions Project/Website/Final_Project/companyblog/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 22 additions & 0 deletions Project/Website/Final_Project/companyblog/core/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from flask import render_template,request,Blueprint
from companyblog.models import BlogPost

core = Blueprint('core',__name__)

@core.route('/')
def index():
'''
This is the home page view. Notice how it uses pagination to show a limited
number of posts by limiting its query size and then calling paginate.
'''
page = request.args.get('page', 1, type=int)
blog_posts = BlogPost.query.order_by(BlogPost.date.desc()).paginate(page=page, per_page=10)
return render_template('index.html',blog_posts=blog_posts)

@core.route('/info')
def info():
'''
Example view of any other "core" page. Such as a info page, about page,
contact page. Any page that doesn't really sync with one of the models.
'''
return render_template('info.html')
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions Project/Website/Final_Project/companyblog/error_pages/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from flask import Blueprint,render_template

error_pages = Blueprint('error_pages',__name__)

@error_pages.app_errorhandler(404)
def error_404(error):
'''
Error for pages not found.
'''
# Notice how we return a tuple!
return render_template('error_pages/404.html'), 404

@error_pages.app_errorhandler(403)
def error_403(error):
'''
Error for trying to access something which is forbidden.
Such as trying to update someone else's blog post.
'''
# Notice how we return a tuple!
return render_template('error_pages/403.html'), 403
64 changes: 64 additions & 0 deletions Project/Website/Final_Project/companyblog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from companyblog import db,login_manager
from datetime import datetime
from werkzeug.security import generate_password_hash,check_password_hash
from flask_login import UserMixin
# By inheriting the UserMixin we get access to a lot of built-in attributes
# which we will be able to call in our views!
# is_authenticated()
# is_active()
# is_anonymous()
# get_id()


# The user_loader decorator allows flask-login to load the current user
# and grab their id.

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

class User(db.Model, UserMixin):

# Create a table in the db
__tablename__ = 'users'

id = db.Column(db.Integer, primary_key = True)
profile_image = db.Column(db.String(20), 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))
# This connects BlogPosts to a User Author.
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):
# https://stackoverflow.com/questions/23432478/flask-generate-password-hash-not-constant-output
return check_password_hash(self.password_hash,password)

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

class BlogPost(db.Model):
# Setup the relationship to the User table
users = db.relationship(User)

# Model for the Blog Posts on Website
id = db.Column(db.Integer, primary_key=True)
# Notice how we connect the BlogPost to a particular author
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} --- Title: {self.title}"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions Project/Website/Final_Project/companyblog/templates/account.html
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% 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) }}">
<p>{{ current_user.email }}</p>
</div>
</div>
<div class="container">
<form method="POST" action = "" enctype="multipart/form-data">
{{ 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-file") }}
</div>
<div class="form-group">
{{ form.submit(class="btn btn-primary") }}
</div>
</form>

</div>

{% endblock content %}
53 changes: 53 additions & 0 deletions Project/Website/Final_Project/companyblog/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<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">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.min.js"></script>
<link rel="icon" href="../static/anonymous logo.jpg" type="image/icon type">
<title>Cyberspace Gateway</title>
</head>
<body>
<div class="container">
<div class="jumbotron text-center">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<ul class="nav">

<li ><a href="{{ url_for('core.index') }}">Home</a></li>
<li ><a href="{{ url_for('core.info') }}">About Us</a></li>
{% if current_user.is_authenticated %}
<li ><a href="{{ url_for('users.logout') }}">Log Out</a></li>
<li ><a href="{{ url_for('users.account') }}">Account</a></li>
<li ><a href="{{ url_for('blog_posts.create_post') }}">Create Post</a></li>
{% else %}
<li ><a href="{{ url_for('users.login') }}">Log In</a></li>
<li ><a href="{{ url_for('users.register') }}">Register</a></li>
{% endif %}

</ul>
</div>
</nav>

<div class="container">
{% block content %}

{% endblock %}
</div>
</div>
</div>

</body>
<nav class="navbar navbar-inverse navbar-fixed-bottom">
<div class="container-fluid">
<h3> contact me: shubhambirmi@hotmail.com </h3>
</div>
</nav>
</html>
45 changes: 45 additions & 0 deletions Project/Website/Final_Project/companyblog/templates/blog_post.html
9089
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends "base.html" %}
{% block content %}
<div class="jumbotron">
<h1>{{ post.title }}</h1>
<h2>Written by: {{post.author.username}}</h2>
<h3>Published: {{ post.date.strftime('%B %d, %Y') }}</h3>
<p>{{post.text}}</p>
{% if post.author == current_user %}
<div>
<a class="btn btn-secondary" href="{{ url_for('blog_posts.update', blog_post_id=post.id) }}">Update</a>
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#del_modal">Delete</button>
</div>
{% endif %}
</div>




<!-- Modal for Pop Up-->
{# https://getbootstrap.com/docs/4.1/components/modal/ #}
{# Notice how the link with the id to the button above! #}
<div class="modal" tabindex="-1" role="dialog" id="del_modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete Post Pop up Modal</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this blog post?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>

<form action="{{ url_for('blog_posts.delete_post', blog_post_id=post.id) }}" method="POST">
<input class="btn btn-danger" type="submit" value="Delete">
</form>
</div>
</div>
</div>
</div>

{% endblock content %}
Loading
0