diff --git a/nlp/__init__.py b/nlp/__init__.py deleted file mode 100644 index db614b4..0000000 --- a/nlp/__init__.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- - -"""Top-level package for nlp.""" - -__author__ = """A Student""" -__email__ = 'student@example.com' -__version__ = '0.1.0' - -# -*- coding: utf-8 -*- -import configparser -import os - -# ~/.nlp/nlp.cfg will contain configuration information for the project, -# such as where data will be downloaded from. -# here is an example. -def write_default_config(path): - w = open(path, 'wt') - w.write('[data]\n') - w.write('url = https://www.dropbox.com/s/o0nxd8pnwy809u2/headlines.csv?dl=1\n') - w.write('file = %s%s%s\n' % (nlp_path, os.path.sep, 'headlines.csv')) - w.close() - -# Find NLP_HOME path -if 'NLP_HOME' in os.environ: - nlp_path = os.environ['NLP_HOME'] -else: - nlp_path = os.environ['HOME'] + os.path.sep + '.nlp' + os.path.sep - -# Make nlp directory if not present -try: - os.makedirs(nlp_path) -except: - pass - -# main config file. -config_path = nlp_path + 'nlp.cfg' -# classifier -clf_path = nlp_path + 'clf.pkl' - -# write default config if not present. -if not os.path.isfile(config_path): - write_default_config(config_path) - -# config variable now accessible throughout project. -config = configparser.RawConfigParser() -config.read(config_path) \ No newline at end of file diff --git a/nlp/app/__init__.py b/nlp/app/__init__.py deleted file mode 100644 index 8c02e85..0000000 --- a/nlp/app/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask import Flask -import os -from .. import nlp_path -app = Flask(__name__) -app.config['SECRET_KEY'] = 'you-will-never-guess' # for CSRF - -from . import routes \ No newline at end of file diff --git a/nlp/app/forms.py b/nlp/app/forms.py deleted file mode 100644 index 5395597..0000000 --- a/nlp/app/forms.py +++ /dev/null @@ -1,12 +0,0 @@ -from flask_wtf import FlaskForm -from wtforms import StringField, SubmitField -from wtforms.validators import DataRequired - -class MyForm(FlaskForm): - class Meta: # Ignoring CSRF security feature. - csrf = False - - input_field = StringField(label='input headline:', id='input_field', - validators=[DataRequired()], - render_kw={'style': 'width:50%'}) - submit = SubmitField('Submit') \ No newline at end of file diff --git a/nlp/app/routes.py b/nlp/app/routes.py deleted file mode 100644 index ec4db3f..0000000 --- a/nlp/app/routes.py +++ /dev/null @@ -1,28 +0,0 @@ -from flask import render_template, flash, redirect, session -from . import app -from .forms import MyForm -from .. import clf_path - -import pickle -import sys - -clf, vec = pickle.load(open(clf_path, 'rb')) -print('read clf %s' % str(clf)) -print('read vec %s' % str(vec)) -labels = ['liberal', 'conservative'] - -@app.route('/', methods=['GET', 'POST']) -@app.route('/index', methods=['GET', 'POST']) -def index(): - form = MyForm() - result = None - if form.validate_on_submit(): - input_field = form.input_field.data - X = vec.transform([input_field]) - pred = clf.predict(X)[0] - proba = clf.predict_proba(X)[0].max() - # flash(input_field) - return render_template('myform.html', title='', form=form, - prediction=labels[pred], confidence='%.2f' % proba) - #return redirect('/index') - return render_template('myform.html', title='', form=form, prediction=None, confidence=None) diff --git a/nlp/app/static/__init__.py b/nlp/app/static/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nlp/app/static/main.css b/nlp/app/static/main.css deleted file mode 100644 index 3277346..0000000 --- a/nlp/app/static/main.css +++ /dev/null @@ -1,20 +0,0 @@ -body { - margin: 50px; - padding: 50px; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - color: #444; -} -/* - * Formatting the header area - */ -header { - background-color: #DFB887; - height: 35px; - width: 100%; - opacity: .9; - margin-bottom: 10px; -} - -label { - color: black; -} \ No newline at end of file diff --git a/nlp/app/templates/__init__.py b/nlp/app/templates/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nlp/app/templates/base.html b/nlp/app/templates/base.html deleted file mode 100644 index d747410..0000000 --- a/nlp/app/templates/base.html +++ /dev/null @@ -1,34 +0,0 @@ - -
- {% if title %} -
- Prediction = {{ prediction }}
Confidence = {{ confidence }}
-