├── .gitattributes
├── Chapter10
├── model
│ ├── .ipynb_checkpoints
│ │ ├── JSONtoCSV-checkpoint.ipynb
│ │ ├── LSTM Model-checkpoint.ipynb
│ │ ├── Security NN-checkpoint.ipynb
│ │ └── Security-with-LSTM-checkpoint.ipynb
│ ├── LSTM Model.ipynb
│ ├── app.py
│ ├── data
│ │ ├── data-full.csv
│ │ └── data.csv
│ ├── lstm-model.h5
│ └── lstm-weights.h5
└── webapp
│ ├── billboard
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── admin.cpython-37.pyc
│ │ ├── forms.cpython-37.pyc
│ │ ├── models.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── views.cpython-37.pyc
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ │ ├── 0001_initial.cpython-37.pyc
│ │ │ └── __init__.cpython-37.pyc
│ ├── models.py
│ ├── templates
│ │ ├── add.html
│ │ ├── base.html
│ │ ├── board.html
│ │ └── login.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
│ ├── db.sqlite3
│ ├── manage.py
│ └── webapp
│ ├── __init__.py
│ ├── __pycache__
│ ├── __init__.cpython-37.pyc
│ ├── settings.cpython-37.pyc
│ ├── urls.cpython-37.pyc
│ └── wsgi.cpython-37.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── Chapter11
├── app
│ ├── Procfile
│ ├── app.py
│ ├── requirements.txt
│ └── templates
│ │ └── index.html
├── data
│ └── heart.csv
└── model
│ ├── .ipynb_checkpoints
│ └── PartialFit-checkpoint.ipynb
│ └── PartialFit.ipynb
├── Chapter12
├── ecomsite
│ ├── db.sqlite3
│ ├── ecomsite
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-37.pyc
│ │ │ ├── settings.cpython-37.pyc
│ │ │ ├── urls.cpython-37.pyc
│ │ │ └── wsgi.cpython-37.pyc
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── manage.py
│ └── orders
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── admin.cpython-37.pyc
│ │ ├── forms.cpython-37.pyc
│ │ ├── models.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── views.cpython-37.pyc
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── forms.py
│ │ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0002_auto_20191205_1259.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ │ ├── 0001_initial.cpython-37.pyc
│ │ │ ├── 0002_auto_20191205_1259.cpython-37.pyc
│ │ │ └── __init__.cpython-37.pyc
│ │ ├── models.py
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
└── ordersui
│ ├── Procfile
│ ├── apiui
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── admin.cpython-37.pyc
│ │ ├── models.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── views.cpython-37.pyc
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ │ └── __init__.cpython-37.pyc
│ ├── models.py
│ ├── templates
│ │ ├── base.html
│ │ ├── index.html
│ │ └── view.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
│ ├── manage.py
│ ├── ordersui
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── settings.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── wsgi.cpython-37.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
│ └── requirements.txt
├── Chapter3
├── app
│ ├── LICENSE
│ ├── flask_app.py
│ ├── flask_both.py
│ ├── flask_cli.py
│ ├── model.json
│ ├── static
│ │ ├── index.js
│ │ └── style.css
│ ├── templates
│ │ └── index.html
│ └── weights.h5
└── model
│ ├── .ipynb_checkpoints
│ └── mnist-keras-checkpoint.ipynb
│ └── mnist-keras.ipynb
├── Chapter4
├── .gitignore
├── README.md
├── index.js
├── iris.json
├── package-lock.json
├── package.json
└── public
│ └── index.html
├── Chapter6
├── CloudVisionClientExample
│ ├── .ipynb_checkpoints
│ │ └── CloudVisionAPIExample-checkpoint.ipynb
│ ├── CloudVisionAPIExample.ipynb
│ └── test.jpg
├── DialogFlow_Python_API_Example
│ ├── .ipynb_checkpoints
│ │ ├── DialogFlowTestIntent-checkpoint.ipynb
│ │ └── Untitled-checkpoint.ipynb
│ └── DialogFlowTestIntent.ipynb
└── GoogleCloudTranslateExample
│ ├── .ipynb_checkpoints
│ └── CloudTranslateAPIExample-checkpoint.ipynb
│ └── CloudTranslateAPIExample.ipynb
├── Chapter7
├── AlexaSkillExample
│ └── lambda_function.py
├── Boto3 Setup.ipynb
├── RekognitionExample
│ ├── .ipynb_checkpoints
│ │ └── Sample-checkpoint.ipynb
│ ├── Sample.ipynb
│ └── image.jpg
└── my_image.jpeg
├── Chapter8
├── CNTKDemo
│ ├── api
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-36.pyc
│ │ │ ├── __init__.cpython-37.pyc
│ │ │ ├── admin.cpython-36.pyc
│ │ │ ├── admin.cpython-37.pyc
│ │ │ ├── models.cpython-36.pyc
│ │ │ ├── models.cpython-37.pyc
│ │ │ ├── urls.cpython-36.pyc
│ │ │ ├── urls.cpython-37.pyc
│ │ │ ├── views.cpython-36.pyc
│ │ │ └── views.cpython-37.pyc
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── migrations
│ │ │ ├── __init__.py
│ │ │ └── __pycache__
│ │ │ │ ├── __init__.cpython-36.pyc
│ │ │ │ └── __init__.cpython-37.pyc
│ │ ├── models.py
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── cntkdemo
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-36.pyc
│ │ │ ├── __init__.cpython-37.pyc
│ │ │ ├── settings.cpython-36.pyc
│ │ │ ├── settings.cpython-37.pyc
│ │ │ ├── urls.cpython-36.pyc
│ │ │ ├── urls.cpython-37.pyc
│ │ │ ├── wsgi.cpython-36.pyc
│ │ │ └── wsgi.cpython-37.pyc
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── data
│ │ └── myModel.model
│ ├── db.sqlite3
│ ├── manage.py
│ ├── static
│ │ ├── index.js
│ │ └── style.css
│ └── templates
│ │ └── api
│ │ └── index.html
├── Face API
│ └── Face API in Python.ipynb
├── Text Analytics API
│ └── Text Analytics API.ipynb
└── sample_image.jpg
├── Chapter9
├── .ipynb_checkpoints
│ ├── Recommendations-checkpoint.ipynb
│ ├── Untitled-checkpoint.ipynb
│ └── recommendation-checkpoint.ipynb
├── Recommendations.ipynb
└── api
│ ├── .DS_Store
│ ├── main.py
│ ├── model.pkl
│ ├── static
│ └── bootstrap.min.css
│ └── templates
│ └── index.html
├── Code for generating plots
└── plotting.py
├── Excel
├── Convolutions.xlsx
├── RNNs.xlsx
└── Toy Dataset.xlsx
├── LICENSE
├── README.md
├── XMLs for figures
├── Big Picture of AI, ML and DL.xml
├── Convolution.xml
├── NeuralNetworkAnatomy (2).xml
├── Overfitting and underfitting.xml
├── RNN Unrolled (1).xml
└── training-error-gen-error.xml
└── _config.yml
/.gitattributes:
--------------------------------------------------------------------------------
1 | Reviews.csv filter=lfs diff=lfs merge=lfs -text
2 | Chapter9/Reviews.csv filter=lfs diff=lfs merge=lfs -text
3 |
--------------------------------------------------------------------------------
/Chapter10/model/.ipynb_checkpoints/Security NN-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [],
3 | "metadata": {},
4 | "nbformat": 4,
5 | "nbformat_minor": 2
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter10/model/.ipynb_checkpoints/Security-with-LSTM-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [],
3 | "metadata": {},
4 | "nbformat": 4,
5 | "nbformat_minor": 2
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter10/model/app.py:
--------------------------------------------------------------------------------
1 | from sklearn.externals import joblib
2 | from flask import Flask, request, jsonify
3 | from string import digits
4 |
5 | import sys
6 | import os
7 | import json
8 | import pandas
9 | import numpy
10 | import optparse
11 | from keras.models import Sequential, load_model
12 | from keras.preprocessing import sequence
13 | from keras.preprocessing.text import Tokenizer
14 | from collections import OrderedDict
15 |
16 | app = Flask(__name__)
17 |
18 | model = load_model('lstm-model.h5')
19 | model.load_weights('lstm-weights.h5')
20 | model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
21 | model._make_predict_function()
22 |
23 | def remove_digits(s: str) -> str:
24 | remove_digits = str.maketrans('', '', digits)
25 | res = s.translate(remove_digits)
26 | return res
27 |
28 | @app.route('/login', methods=['GET', 'POST'])
29 | def login():
30 | req = dict(request.headers)
31 | item = {}
32 | item["method"] = str(request.method)
33 | item["query"] = str(request.query_string)
34 | item["path"] = str(request.path)
35 | item["statusCode"] = 200
36 | item["requestPayload"] = []
37 |
38 | X = numpy.array([json.dumps(item)])
39 | log_entry = "store"
40 |
41 | tokenizer = Tokenizer(filters='\t\n', char_level=True)
42 | tokenizer.fit_on_texts(X)
43 | seq = tokenizer.texts_to_sequences([log_entry])
44 | max_log_length = 1024
45 | log_entry_processed = sequence.pad_sequences(seq, maxlen=max_log_length)
46 |
47 | prediction = model.predict(log_entry_processed)
48 | print(prediction)
49 | response = {'result': float(prediction[0][0])}
50 | return jsonify(response)
51 |
52 | if __name__ == '__main__':
53 | app.run(port=9000, debug=True)
--------------------------------------------------------------------------------
/Chapter10/model/lstm-model.h5:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/model/lstm-model.h5
--------------------------------------------------------------------------------
/Chapter10/model/lstm-weights.h5:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/model/lstm-weights.h5
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/__init__.py
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/__pycache__/admin.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/__pycache__/admin.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/__pycache__/forms.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/__pycache__/forms.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/__pycache__/models.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/__pycache__/models.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/__pycache__/urls.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/__pycache__/urls.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/__pycache__/views.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/__pycache__/views.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class BillboardConfig(AppConfig):
5 | name = 'billboard'
6 |
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 2.0.8 on 2019-09-06 14:10
2 |
3 | from django.conf import settings
4 | from django.db import migrations, models
5 | import django.utils.timezone
6 |
7 |
8 | class Migration(migrations.Migration):
9 |
10 | initial = True
11 |
12 | dependencies = [
13 | migrations.swappable_dependency(settings.AUTH_USER_MODEL),
14 | ]
15 |
16 | operations = [
17 | migrations.CreateModel(
18 | name='Bills',
19 | fields=[
20 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21 | ('billName', models.CharField(default='New Bill', max_length=100, verbose_name='Bill Name')),
22 | ('billDesc', models.TextField()),
23 | ('billTime', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
24 | ('user', models.ForeignKey(on_delete='CASCADE', to=settings.AUTH_USER_MODEL)),
25 | ],
26 | options={
27 | 'db_table': 'bills',
28 | },
29 | ),
30 | ]
31 |
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/migrations/__init__.py
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/migrations/__pycache__/0001_initial.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/migrations/__pycache__/0001_initial.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/migrations/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/billboard/migrations/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | from django.utils.timezone import now
4 | from django.contrib.auth.models import User
5 |
6 | # Create your models here.
7 | class Bills(models.Model):
8 | billName = models.CharField("Bill Name", blank=False, max_length=100, default="New Bill")
9 | user = models.ForeignKey(User, on_delete="CASCADE")
10 | billDesc = models.TextField("Bill Description")
11 | billTime = models.DateTimeField(default=now, editable=False)
12 |
13 | class Meta:
14 | db_table = "bills"
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/templates/add.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 | {% block content %}
3 |
24 |
25 |
33 | {% endblock %}
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/templates/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | BillBoard Test App
11 |
12 |
35 |
36 |
37 |
38 |
54 |
55 |
56 |
57 |
58 | {% block content %}
59 | {% endblock %}
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/templates/board.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 | {% block content %}
3 |
4 |
5 | {% for bill in bills %}
6 |
16 | {% endfor %}
17 |
18 |
19 | {% endblock %}
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/templates/login.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 | {% block content %}
3 |
24 | {% endblock %}
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 | from django.contrib.auth.decorators import login_required
3 |
4 | from . import views
5 |
6 | urlpatterns = [
7 | path('', login_required(views.board), name='View Board'),
8 | path('add', login_required(views.addbill), name='Add Bill'),
9 | path('login', views.loginView, name='Login'),
10 | path('logout', views.logoutView, name='Logout'),
11 | ]
--------------------------------------------------------------------------------
/Chapter10/webapp/billboard/views.py:
--------------------------------------------------------------------------------
1 | from django.shortcuts import render, render_to_response
2 | from django.http import HttpResponse
3 | from django.template import loader
4 |
5 | import datetime
6 |
7 | from django.shortcuts import redirect
8 | from django.contrib.auth import authenticate, login, logout
9 |
10 | from django.conf import settings
11 | from django.urls import reverse_lazy
12 | from django.views import generic
13 |
14 | from django.contrib.auth.models import User
15 | from .models import Bills
16 |
17 | from django.conf import settings
18 |
19 | import urllib
20 | import ssl
21 | import json
22 |
23 | def board(request):
24 | template = loader.get_template('board.html')
25 | context = {}
26 | context["isLogged"] = 1
27 |
28 | Bill = Bills.objects.all()
29 |
30 | context["bills"] = Bill
31 |
32 | return HttpResponse(template.render(context, request))
33 |
34 | def addbill(request):
35 | print(request.POST)
36 |
37 | if request.POST:
38 | recaptcha_response = request.POST.get('g-recaptcha-response')
39 | url = 'https://www.google.com/recaptcha/api/siteverify'
40 | values = {
41 | 'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
42 | 'response': recaptcha_response
43 | }
44 |
45 | # This restores the same behavior as before.
46 | context = ssl._create_unverified_context()
47 | data = urllib.parse.urlencode(values).encode()
48 | req = urllib.request.Request(url, data=data)
49 | response = urllib.request.urlopen(req, context=context)
50 | result = json.loads(response.read().decode())
51 |
52 | if result['success']:
53 | billName = request.POST['billname']
54 | billDesc = request.POST['billdesc']
55 | Bill = Bills.objects.create(billName=billName, user=request.user, billDesc=billDesc)
56 | Bill.save()
57 | return redirect('/')
58 | else:
59 | print(result)
60 | return redirect('/add')
61 | else:
62 | template = loader.get_template('add.html')
63 | context = {}
64 | context["isLogged"] = 1
65 |
66 | return HttpResponse(template.render(context, request))
67 |
68 | def loginView(request):
69 | if request.user.is_authenticated:
70 | return redirect('/')
71 | else:
72 | if request.POST:
73 | username = request.POST['username']
74 | password = request.POST['password']
75 | user = authenticate(request, username=username, password=password)
76 | if user is not None:
77 | url = 'http://127.0.0.1:9000/login'
78 | values = {
79 | 'username': username,
80 | 'password': password
81 | }
82 | data = urllib.parse.urlencode(values).encode()
83 | req = urllib.request.Request(url, data=data)
84 | response = urllib.request.urlopen(req)
85 | result = json.loads(response.read().decode())
86 | print(result)
87 | if result['result'] > 0.20:
88 | login(request, user)
89 | return redirect('/')
90 | else:
91 | return redirect('/logout')
92 | else:
93 | return redirect('/logout')
94 | else:
95 | template = loader.get_template('login.html')
96 | context = {}
97 | return HttpResponse(template.render(context, request))
98 |
99 |
100 | def logoutView(request):
101 | logout(request)
102 | return redirect('/')
--------------------------------------------------------------------------------
/Chapter10/webapp/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/db.sqlite3
--------------------------------------------------------------------------------
/Chapter10/webapp/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == "__main__":
6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webapp.settings")
7 | try:
8 | from django.core.management import execute_from_command_line
9 | except ImportError as exc:
10 | raise ImportError(
11 | "Couldn't import Django. Are you sure it's installed and "
12 | "available on your PYTHONPATH environment variable? Did you "
13 | "forget to activate a virtual environment?"
14 | ) from exc
15 | execute_from_command_line(sys.argv)
16 |
--------------------------------------------------------------------------------
/Chapter10/webapp/webapp/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/webapp/__init__.py
--------------------------------------------------------------------------------
/Chapter10/webapp/webapp/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/webapp/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/webapp/__pycache__/settings.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/webapp/__pycache__/settings.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/webapp/__pycache__/urls.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/webapp/__pycache__/urls.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/webapp/__pycache__/wsgi.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter10/webapp/webapp/__pycache__/wsgi.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter10/webapp/webapp/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for webapp project.
3 |
4 | Generated by 'django-admin startproject' using Django 2.0.8.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.0/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/2.0/ref/settings/
11 | """
12 |
13 | import os
14 |
15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 |
18 |
19 | # Quick-start development settings - unsuitable for production
20 | # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
21 |
22 | # SECURITY WARNING: keep the secret key used in production secret!
23 | SECRET_KEY = '_lx#_t9(3k-&k%=$g$tfj_k-xht9i215&sc37ahvvma+9#h*f$'
24 |
25 | # SECURITY WARNING: don't run with debug turned on in production!
26 | DEBUG = True
27 |
28 | ALLOWED_HOSTS = []
29 |
30 |
31 | # Application definition
32 |
33 | INSTALLED_APPS = [
34 | 'billboard',
35 | 'django.contrib.admin',
36 | 'django.contrib.auth',
37 | 'django.contrib.contenttypes',
38 | 'django.contrib.sessions',
39 | 'django.contrib.messages',
40 | 'django.contrib.staticfiles',
41 | ]
42 |
43 | MIDDLEWARE = [
44 | 'django.middleware.security.SecurityMiddleware',
45 | 'django.contrib.sessions.middleware.SessionMiddleware',
46 | 'django.middleware.common.CommonMiddleware',
47 | 'django.middleware.csrf.CsrfViewMiddleware',
48 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
49 | 'django.contrib.messages.middleware.MessageMiddleware',
50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
51 | ]
52 |
53 | ROOT_URLCONF = 'webapp.urls'
54 |
55 | TEMPLATES = [
56 | {
57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
58 | 'DIRS': [],
59 | 'APP_DIRS': True,
60 | 'OPTIONS': {
61 | 'context_processors': [
62 | 'django.template.context_processors.debug',
63 | 'django.template.context_processors.request',
64 | 'django.contrib.auth.context_processors.auth',
65 | 'django.contrib.messages.context_processors.messages',
66 | ],
67 | },
68 | },
69 | ]
70 |
71 | WSGI_APPLICATION = 'webapp.wsgi.application'
72 |
73 |
74 | # Database
75 | # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
76 |
77 | DATABASES = {
78 | 'default': {
79 | 'ENGINE': 'django.db.backends.sqlite3',
80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81 | }
82 | }
83 |
84 |
85 | # Password validation
86 | # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
87 |
88 | AUTH_PASSWORD_VALIDATORS = [
89 | {
90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91 | },
92 | {
93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94 | },
95 | {
96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97 | },
98 | {
99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100 | },
101 | ]
102 |
103 |
104 | # Internationalization
105 | # https://docs.djangoproject.com/en/2.0/topics/i18n/
106 |
107 | LANGUAGE_CODE = 'en-us'
108 |
109 | TIME_ZONE = 'UTC'
110 |
111 | USE_I18N = True
112 |
113 | USE_L10N = True
114 |
115 | USE_TZ = True
116 |
117 |
118 | # Static files (CSS, JavaScript, Images)
119 | # https://docs.djangoproject.com/en/2.0/howto/static-files/
120 |
121 | STATIC_URL = '/static/'
122 |
123 | STATICFILES_DIRS = [
124 | os.path.join(BASE_DIR, "static")
125 | ]
126 |
127 | LOGIN_URL = "/login"
128 | LOGIN_REDIRECT_URL = '/'
129 | LOGOUT_REDIRECT_URL = '/logout'
130 |
131 | GOOGLE_RECAPTCHA_SECRET_KEY = '6Lfi6ncUAAAAANJYkMC66skocDgA1REblmx0-3B2'
--------------------------------------------------------------------------------
/Chapter10/webapp/webapp/urls.py:
--------------------------------------------------------------------------------
1 | """webapp URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.urls import include, path
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 | """
16 | from django.contrib import admin
17 | from django.urls import path, include
18 |
19 | urlpatterns = [
20 | path('', include('billboard.urls')),
21 | path('admin/', admin.site.urls),
22 | ]
23 |
--------------------------------------------------------------------------------
/Chapter10/webapp/webapp/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for webapp project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webapp.settings")
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/Chapter11/app/Procfile:
--------------------------------------------------------------------------------
1 | web: gunicorn app:app
--------------------------------------------------------------------------------
/Chapter11/app/app.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, request, jsonify, render_template
2 |
3 | import pandas as pd
4 | import numpy as np
5 | from sklearn.model_selection import train_test_split
6 | from sklearn.preprocessing import StandardScaler
7 | from sklearn.neural_network import MLPClassifier
8 |
9 | np.random.seed(5)
10 |
11 | df = pd.read_csv("https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/master/Chapter11/data/heart.csv")
12 |
13 | X = df.drop("target",axis=1)
14 | y = df["target"]
15 |
16 | X = StandardScaler().fit_transform(X)
17 | X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.20,random_state=0)
18 |
19 | clf = MLPClassifier(max_iter=200)
20 |
21 | for i in range(100):
22 | xt = X_train[i].reshape(1, -1)
23 | yt = y_train.values[[i]]
24 | clf = clf.partial_fit(xt, yt, classes=[0,1])
25 | if i > 0 and i % 25 == 0 or i == len(X_train) - 1:
26 | score = clf.score(X_test, y_test)
27 | print("Iters ", i, ": ", score)
28 |
29 | score = clf.score(X_test, y_test)
30 |
31 | app = Flask(__name__)
32 |
33 | start_at = 100
34 |
35 | @app.route('/train_batch', methods=['GET', 'POST'])
36 | def train_batch():
37 | global start_at, clf, X_train, y_train, X_test, y_test, score
38 | for i in range(start_at, min(start_at+25, len(X_train))):
39 | xt = X_train[i].reshape(1, -1)
40 | yt = y_train.values[[i]]
41 | clf = clf.partial_fit(xt, yt, classes=[0,1])
42 |
43 | score = clf.score(X_test, y_test)
44 |
45 | start_at += 25
46 |
47 | response = {'result': float(round(score, 5)), 'remaining': len(X_train) - start_at}
48 |
49 | return jsonify(response)
50 |
51 | @app.route('/reset', methods=['GET', 'POST'])
52 | def reset():
53 | global start_at, clf, X_train, y_train, X_test, y_test, score
54 | start_at = 0
55 | del clf
56 | clf = MLPClassifier(max_iter=200)
57 | for i in range(start_at, start_at+1):
58 | xt = X_train[i].reshape(1, -1)
59 | yt = y_train.values[[i]]
60 | clf = clf.partial_fit(xt, yt, classes=[0,1])
61 |
62 | score = clf.score(X_test, y_test)
63 |
64 | start_at += 1
65 |
66 | response = {'result': float(round(score, 5)), 'remaining': len(X_train) - start_at}
67 |
68 | return jsonify(response)
69 |
70 | @app.route('/')
71 | def index():
72 | global score, X_train
73 | rem = (len(X_train) - start_at) > 0
74 |
75 | return render_template("index.html", score=round(score, 5), remain = rem)
76 |
77 | if __name__ == '__main__':
78 | app.run()
--------------------------------------------------------------------------------
/Chapter11/app/requirements.txt:
--------------------------------------------------------------------------------
1 | Flask==1.0.2
2 | Flask-Cors==3.0.7
3 | Flask-Jsonpify==1.5.0
4 | Flask-RESTful==0.3.7
5 | Flask-WTF==0.14.2
6 | gunicorn==19.9.0
7 | gym==0.14.0
8 | h5py==2.8.0
9 | heapdict==1.0.0
10 | html5lib==1.0.1
11 | httplib2==0.13.1
12 | hyperlink==18.0.0
13 | idna==2.8
14 | imageio==2.4.1
15 | imagesize==1.1.0
16 | importlib-metadata==0.6
17 | imutils==0.5.2
18 | incremental==17.5.0
19 | intervaltree==3.0.2
20 | numpy==1.17.1
21 | numpydoc==0.8.0
22 | oauth2client==4.1.3
23 | olefile==0.46
24 | packaging==18.0
25 | pandas==0.23.3
26 | pandocfilters==1.4.2
27 | parsel==1.5.1
28 | parso==0.3.1
29 | partd==0.3.9
30 | path.py==11.5.0
31 | pathlib2==2.3.3
32 | patsy==0.5.1
33 | pbr==5.1.3
34 | pep8==1.7.1
35 | pexpect==4.6.0
36 | pickleshare==0.7.5
37 | Pillow==6.2.0
38 | pkginfo==1.4.2
39 | pluggy==0.8.0
40 | ply==3.11
41 | prometheus-client==0.5.0
42 | promise==2.2.1
43 | prompt-toolkit==2.0.7
44 | protobuf==3.7.1
45 | psutil==5.4.8
46 | pyOpenSSL==18.0.0
47 | pyparsing==2.3.0
48 | pypng==0.0.20
49 | PySocks==1.6.8
50 | pytest==4.0.2
51 | pytest-arraydiff==0.3
52 | pytest-astropy==0.5.0
53 | pytest-doctestplus==0.2.0
54 | pytest-openfiles==0.3.1
55 | pytest-remotedata==0.3.1
56 | pytest-runner==4.4
57 | python-crontab==2.3.6
58 | python-dateutil==2.7.5
59 | python-Levenshtein==0.12.0
60 | python-utils==2.3.0
61 | pytz==2018.7
62 | PyYAML==3.13
63 | pyzmq==17.1.2
64 | QtAwesome==0.5.3
65 | qtconsole==4.4.3
66 | queuelib==1.5.0
67 | requests==2.21.0
68 | requests-file==1.4.3
69 | requests-toolbelt==0.9.1
70 | resampy==0.2.2
71 | rope==0.11.0
72 | rsa==4.0
73 | ruamel-yaml==0.15.46
74 | s3transfer==0.2.0
75 | scikit-image==0.14.1
76 | scikit-learn==0.21.3
77 | scipy==1.3.1
78 | Scrapy==1.5.2
79 | seaborn==0.9.0
80 | SecretStorage==3.1.0
81 | selenium==3.141.0
82 | Send2Trash==1.5.0
83 | service-identity==18.1.0
84 | simplegeneric==0.8.1
85 | singledispatch==3.4.0.3
86 | six==1.12.0
87 | sk-video==1.1.10
88 | sky==0.0.201
89 | snowballstemmer==1.2.1
90 | sonnet==0.1.6
91 | sortedcollections==1.0.1
92 | sortedcontainers==2.1.0
93 | SoundFile==0.10.2
94 | sox==1.3.7
95 | statsmodels==0.9.0
96 | sympy==1.3
97 | tables==3.4.4
98 | tblib==1.3.2
99 | termcolor==1.1.0
100 | terminado==0.8.1
101 | testpath==0.4.2
102 | tldextract==2.2.1
103 | toml==0.10.0
104 | toolz==0.9.0
105 | tornado==4.5.3
106 | tox==3.7.0
107 | tqdm==4.28.1
108 | traitlets==4.3.2
109 | twine==1.13.0
110 | Twisted==18.9.0
111 | unicodecsv==0.14.1
112 | uritemplate==3.0.0
113 | urllib3==1.24.1
114 | utils==0.9.0
115 | virtualenv==16.4.3
116 | w3lib==1.20.0
117 | wcwidth==0.1.7
118 | webencodings==0.5.1
119 | Werkzeug==0.14.1
120 | widgetsnbextension==3.4.2
121 | wrapt==1.10.11
122 | WTForms==2.2.1
123 | wurlitzer==1.0.2
124 | xlrd==1.2.0
125 | XlsxWriter==1.1.2
126 | xlwt==1.3.0
127 | yarl==1.3.0
128 | zict==0.1.3
129 | zope.interface==4.6.0
--------------------------------------------------------------------------------
/Chapter11/app/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Online Training Example
5 |
6 |
7 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | Current Accuracy: {{ score }}
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | {% if remain %}
99 |
100 | {% else %}
101 |
102 | {% endif %}
103 |
104 |
105 |
106 |
107 |
108 |
165 |
--------------------------------------------------------------------------------
/Chapter12/ecomsite/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/db.sqlite3
--------------------------------------------------------------------------------
/Chapter12/ecomsite/ecomsite/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/ecomsite/__init__.py
--------------------------------------------------------------------------------
/Chapter12/ecomsite/ecomsite/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/ecomsite/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/ecomsite/__pycache__/settings.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/ecomsite/__pycache__/settings.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/ecomsite/__pycache__/urls.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/ecomsite/__pycache__/urls.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/ecomsite/__pycache__/wsgi.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/ecomsite/__pycache__/wsgi.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/ecomsite/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for ecomsite project.
3 |
4 | Generated by 'django-admin startproject' using Django 2.2.5.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.2/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/2.2/ref/settings/
11 | """
12 |
13 | import os
14 |
15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 |
18 |
19 | # Quick-start development settings - unsuitable for production
20 | # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
21 |
22 | # SECURITY WARNING: keep the secret key used in production secret!
23 | SECRET_KEY = 'cd83*9d_cm34n=lgi46rc&x*z3c3*n2fva&u9ak0uhuv0sz85('
24 |
25 | # SECURITY WARNING: don't run with debug turned on in production!
26 | DEBUG = True
27 |
28 | ALLOWED_HOSTS = []
29 |
30 |
31 | # Application definition
32 |
33 | INSTALLED_APPS = [
34 | 'orders',
35 | 'django.contrib.admin',
36 | 'django.contrib.auth',
37 | 'django.contrib.contenttypes',
38 | 'django.contrib.sessions',
39 | 'django.contrib.messages',
40 | 'django.contrib.staticfiles',
41 | ]
42 |
43 | MIDDLEWARE = [
44 | 'django.middleware.security.SecurityMiddleware',
45 | 'django.contrib.sessions.middleware.SessionMiddleware',
46 | 'django.middleware.common.CommonMiddleware',
47 | 'django.middleware.csrf.CsrfViewMiddleware',
48 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
49 | 'django.contrib.messages.middleware.MessageMiddleware',
50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
51 | ]
52 |
53 | ROOT_URLCONF = 'ecomsite.urls'
54 |
55 | TEMPLATES = [
56 | {
57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
58 | 'DIRS': [],
59 | 'APP_DIRS': True,
60 | 'OPTIONS': {
61 | 'context_processors': [
62 | 'django.template.context_processors.debug',
63 | 'django.template.context_processors.request',
64 | 'django.contrib.auth.context_processors.auth',
65 | 'django.contrib.messages.context_processors.messages',
66 | ],
67 | },
68 | },
69 | ]
70 |
71 | WSGI_APPLICATION = 'ecomsite.wsgi.application'
72 |
73 |
74 | # Database
75 | # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
76 |
77 | DATABASES = {
78 | 'default': {
79 | 'ENGINE': 'django.db.backends.sqlite3',
80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81 | }
82 | }
83 |
84 |
85 | # Password validation
86 | # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
87 |
88 | AUTH_PASSWORD_VALIDATORS = [
89 | {
90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91 | },
92 | {
93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94 | },
95 | {
96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97 | },
98 | {
99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100 | },
101 | ]
102 |
103 |
104 | # Internationalization
105 | # https://docs.djangoproject.com/en/2.2/topics/i18n/
106 |
107 | LANGUAGE_CODE = 'en-us'
108 |
109 | TIME_ZONE = 'UTC'
110 |
111 | USE_I18N = True
112 |
113 | USE_L10N = True
114 |
115 | USE_TZ = True
116 |
117 |
118 | # Static files (CSS, JavaScript, Images)
119 | # https://docs.djangoproject.com/en/2.2/howto/static-files/
120 |
121 | STATIC_URL = '/static/'
--------------------------------------------------------------------------------
/Chapter12/ecomsite/ecomsite/urls.py:
--------------------------------------------------------------------------------
1 | """ecomsite path Configuration
2 |
3 | The `pathpatterns` list routes paths to views. For more information please see:
4 | https://docs.djangoproject.com/en/2.2/topics/http/paths/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a path to pathpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a path to pathpatterns: path('', Home.as_view(), name='home')
12 | Including another pathconf
13 | 1. Import the include() function: from django.paths import include, path
14 | 2. Add a path to pathpatterns: path('blog/', include('blog.paths'))
15 | """
16 | from django.contrib import admin
17 | from django.urls import path, include
18 |
19 | urlpatterns = [
20 | path('', include('orders.urls')),
21 | path('admin/', admin.site.urls),
22 | ]
--------------------------------------------------------------------------------
/Chapter12/ecomsite/ecomsite/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for ecomsite project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecomsite.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/Chapter12/ecomsite/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecomsite.settings')
9 | try:
10 | from django.core.management import execute_from_command_line
11 | except ImportError as exc:
12 | raise ImportError(
13 | "Couldn't import Django. Are you sure it's installed and "
14 | "available on your PYTHONPATH environment variable? Did you "
15 | "forget to activate a virtual environment?"
16 | ) from exc
17 | execute_from_command_line(sys.argv)
18 |
19 |
20 | if __name__ == '__main__':
21 | main()
22 |
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/__init__.py
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/__pycache__/admin.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/__pycache__/admin.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/__pycache__/forms.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/__pycache__/forms.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/__pycache__/models.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/__pycache__/models.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/__pycache__/urls.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/__pycache__/urls.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/__pycache__/views.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/__pycache__/views.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class OrdersConfig(AppConfig):
5 | name = 'orders'
6 |
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/forms.py:
--------------------------------------------------------------------------------
1 | from django.forms import ModelForm
2 | from django import forms
3 | from .models import Order
4 |
5 | class OrderForm(ModelForm):
6 | OPTIONS = (
7 | ('Confirmed', 'Confirmed'),
8 | ('Shipping', 'Shipping'),
9 | ('Delivered', 'Delivered'),
10 | )
11 | order_status = forms.TypedChoiceField(required=False, choices=OPTIONS, widget=forms.RadioSelect)
12 |
13 | class Meta:
14 | model = Order
15 | fields = ['name','phone','address','product_id','amount','order_status']
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 2.2.5 on 2019-12-05 12:12
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | initial = True
9 |
10 | dependencies = [
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Order',
16 | fields=[
17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18 | ('name', models.CharField(max_length=200)),
19 | ('phone', models.CharField(max_length=20)),
20 | ('address', models.TextField()),
21 | ('delivery_date', models.DateField(blank=True)),
22 | ('product_id', models.TextField()),
23 | ('amount', models.IntegerField()),
24 | ('order_status', models.CharField(max_length=50)),
25 | ],
26 | ),
27 | ]
28 |
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/migrations/0002_auto_20191205_1259.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 2.2.5 on 2019-12-05 12:59
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('orders', '0001_initial'),
10 | ]
11 |
12 | operations = [
13 | migrations.RemoveField(
14 | model_name='order',
15 | name='delivery_date',
16 | ),
17 | migrations.AlterField(
18 | model_name='order',
19 | name='name',
20 | field=models.CharField(max_length=500),
21 | ),
22 | migrations.AlterField(
23 | model_name='order',
24 | name='order_status',
25 | field=models.CharField(default='Confirmed', max_length=20),
26 | ),
27 | migrations.AlterField(
28 | model_name='order',
29 | name='phone',
30 | field=models.CharField(max_length=15),
31 | ),
32 | migrations.AlterField(
33 | model_name='order',
34 | name='product_id',
35 | field=models.IntegerField(),
36 | ),
37 | ]
38 |
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/migrations/__init__.py
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/migrations/__pycache__/0001_initial.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/migrations/__pycache__/0001_initial.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/migrations/__pycache__/0002_auto_20191205_1259.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/migrations/__pycache__/0002_auto_20191205_1259.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/migrations/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ecomsite/orders/migrations/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | # Create your models here.
4 | class Order (models.Model):
5 | name = models.CharField(max_length=500)
6 | phone = models.CharField(max_length=15)
7 | address = models.TextField()
8 | product_id = models.IntegerField()
9 | amount = models.IntegerField()
10 | order_status = models.CharField(max_length=20, default="Confirmed")
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 |
3 | from . import views
4 |
5 | urlpatterns = [
6 | path('', views.indexView, name='indexView'),
7 | path('', views.viewOrder, name='viewOrder'),
8 | path('add', views.addOrder, name='addOrder'),
9 | path('edit/', views.editOrder, name='editOrder'),
10 | path('delete/', views.deleteOrder, name='deleteOrder'),
11 | ]
--------------------------------------------------------------------------------
/Chapter12/ecomsite/orders/views.py:
--------------------------------------------------------------------------------
1 | from django.shortcuts import render, redirect
2 | from .models import Order
3 | from .forms import OrderForm
4 | from django.http import JsonResponse
5 |
6 | def indexView(request):
7 | orders = Order.objects.all()
8 | orders = list(orders.values())
9 | return JsonResponse({'orders': orders})
10 |
11 | def viewOrder(request, orderId):
12 | order = Order.objects.filter(id=orderId)
13 | order = list(order.values())
14 | return JsonResponse({'order': order})
15 |
16 | def addOrder(request):
17 | if request.POST:
18 | form = OrderForm(request.POST)
19 | if form.is_valid():
20 | if form.save():
21 | return JsonResponse('Order created')
22 | else:
23 | return JsonResponse('There was an error')
24 | else:
25 | return JsonResponse('Invalid form details')
26 | else:
27 | return JsonResponse('Invalid form details')
28 |
29 | def editOrder(request, orderId):
30 | order = Order.objects.get(id=orderId)
31 | if request.POST:
32 | form = OrderForm(request.POST, instance=order)
33 | if form.is_valid():
34 | if form.save():
35 | return JsonResponse('Order updated')
36 | else:
37 | return JsonResponse('There was an error')
38 | else:
39 | return JsonResponse('Invalid form details')
40 | else:
41 | return JsonResponse('Invalid form details')
42 |
43 | def deleteOrder(request, orderId):
44 | order = Order.objects.get(id=orderId)
45 | order.delete()
46 | return JsonResponse('Order deleted')
--------------------------------------------------------------------------------
/Chapter12/ordersui/Procfile:
--------------------------------------------------------------------------------
1 | web: gunicorn ordersui.wsgi
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ordersui/apiui/__init__.py
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ordersui/apiui/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/__pycache__/admin.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ordersui/apiui/__pycache__/admin.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/__pycache__/models.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ordersui/apiui/__pycache__/models.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/__pycache__/urls.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ordersui/apiui/__pycache__/urls.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/__pycache__/views.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ordersui/apiui/__pycache__/views.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class ApiuiConfig(AppConfig):
5 | name = 'apiui'
6 |
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ordersui/apiui/migrations/__init__.py
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/migrations/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/1aa7ddbda40af4890c8006dcec0225adb4f0a66f/Chapter12/ordersui/apiui/migrations/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | # Create your models here.
4 |
--------------------------------------------------------------------------------
/Chapter12/ordersui/apiui/templates/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
27 |
28 |
29 | {% block body %}
30 | {% endblock %}
31 |
32 |
33 | Ask a question
34 |
88 |
89 |