Skip to content

Commit

Permalink
django web app implementation started and ml model integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
prasad5141 committed Jan 19, 2020
1 parent 9eaa58d commit 37045c1
Show file tree
Hide file tree
Showing 28 changed files with 258 additions and 0 deletions.
Empty file added db.sqlite3
Empty file.
21 changes: 21 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'titanicsurvival.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1> Titanic Survival Prediction algorithm</h1>
5 changes: 5 additions & 0 deletions templates/predict.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<form method="POST" action="">
{% csrf_token %}
{{form.as_p}}
<button class="button" type="submit"> Submit</button>
</form>
Binary file added titanic.pkl
Binary file not shown.
Empty file added titanicsurvival/__init__.py
Empty file.
Binary file added titanicsurvival/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file added titanicsurvival/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file added titanicsurvival/__pycache__/wsgi.cpython-37.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions titanicsurvival/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for titanicsurvival project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'titanicsurvival.settings')

application = get_asgi_application()
121 changes: 121 additions & 0 deletions titanicsurvival/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"""
Django settings for titanicsurvival project.
Generated by 'django-admin startproject' using Django 3.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates')

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'e^vb$7ee7t3xdbpb5@bn$4e-a2182a%0v6crt0(_aotmo$jnkm'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'titanicsurvivalapp'
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'titanicsurvival.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATES_DIR],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'titanicsurvival.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
24 changes: 24 additions & 0 deletions titanicsurvival/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""titanicsurvival URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from titanicsurvivalapp import views

urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name="home"),
path('predict', views.predict, name="predict")
]
16 changes: 16 additions & 0 deletions titanicsurvival/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for titanicsurvival project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'titanicsurvival.settings')

application = get_wsgi_application()
Empty file added titanicsurvivalapp/__init__.py
Empty file.
Binary file not shown.
Binary file added titanicsurvivalapp/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file added titanicsurvivalapp/__pycache__/forms.cpython-37.pyc
Binary file not shown.
Binary file added titanicsurvivalapp/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file added titanicsurvivalapp/__pycache__/views.cpython-37.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions titanicsurvivalapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions titanicsurvivalapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class TitanicsurvivalappConfig(AppConfig):
name = 'titanicsurvivalapp'
17 changes: 17 additions & 0 deletions titanicsurvivalapp/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django import forms


class InputForm(forms.Form):
P_class = (
('1', '1st Class'),
('2', '2nd Class'),
('3', '3rd Class')
)
gender = (
('0', 'Female'),
('1', 'Male')
)
name = forms.CharField(required=True)
passenger_class = forms.ChoiceField(choices=P_class, required=True)
age = forms.IntegerField(required=True)
gender = forms.ChoiceField(choices=gender)
Empty file.
Binary file not shown.
3 changes: 3 additions & 0 deletions titanicsurvivalapp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions titanicsurvivalapp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
23 changes: 23 additions & 0 deletions titanicsurvivalapp/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.shortcuts import render
import pickle
import pandas as pd
from .forms import *

# Create your views here.

def home(request):
titanic_model = pickle.load(open("titanic.pkl", "rb"))
input_data = [[2.0, 18.0, 0.0, 1.0]]
data = pd.DataFrame(input_data, columns=['Pclass','Age', 'Sex_female', 'Sex_male'])
print(titanic_model.predict(data))
return render(request, 'home.html')

def predict(request):
if request.method == "GET":
form = InputForm()
return render(request, 'predict.html', {"form":form})
if request.method == "POST":
form = InputForm(request.POST)
if form.is_valid():
print(form['gender'].value())
return render(request, 'predict.html')

0 comments on commit 37045c1

Please sign in to comment.