<commit_before>from flask import Flask, render_template, flash
from flask_wtf import Form
from flask_wtf.file import FileField
from tools import s3_upload, store_locally
import json 

app = Flask(__name__)
app.config.from_object('config')


class UploadForm(Form):
    example = FileField('Example File')


@app.route('/', methods=['POST', 'GET'])
def upload_page():
    form = UploadForm(csrf_enabled=False)
    upload_file = form.example
    if form.validate_on_submit():
        output = store_locally(upload_file)
        response = {}
        if output is not None:
            response['url'] = output
            return json.dumps(response, indent=4)
        else:
            response['url'] = None
            return json.dumps(response, indent=4), app.config["INVALID_DATA"] 
    return render_template('example.html', form=form)    

if __name__ == '__main__':
    app.run(host=app.config["HOST"], port=app.config["PORT"], debug=app.config["DEBUG"])
<commit_msg>Use a production ready server; no disk polling<commit_after>from os import environ
from flask import Flask, render_template, flash
from flask_wtf import Form
from flask_wtf.file import FileField
from tools import s3_upload, store_locally
import json 

app = Flask(__name__)
app.config.from_object('config')


class UploadForm(Form):
    example = FileField('Example File')


@app.route('/', methods=['POST', 'GET'])
def upload_page():
    form = UploadForm(csrf_enabled=False)
    upload_file = form.example
    if form.validate_on_submit():
        output = store_locally(upload_file)
        response = {}
        if output is not None:
            response['url'] = output
            return json.dumps(response, indent=4)
        else:
            response['url'] = None
            return json.dumps(response, indent=4), app.config["INVALID_DATA"] 
    return render_template('example.html', form=form)    

if __name__ == '__main__':
    if environ.has_key('FLASK_ENV') and environ['FLASK_ENV'] == 'production':
        from gevent.wsgi import WSGIServer
        WSGIServer((app.config["HOST"], app.config["PORT"]), app).serve_forever()
    else:
        app.run(host=app.config["HOST"], port=app.config["PORT"], debug=app.config["DEBUG"])

{'fraction_non_alphanumeric': 0.12248468941382328, 'fraction_numerical': 0.0026246719160104987, 'mean_word_length': 3.188644688644689, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1278767', 'n_tokens_mistral': 729, 'n_tokens_neox': 684, 'n_words': 162}