-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (30 loc) · 1 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, abort,jsonify, request, render_template, redirect, url_for
import json,sys,urllib2,os
from functools import wraps
import analyze
app = Flask(__name__)
app.classifier = analyze.analyze()
def jsonp(f):
"""Wraps JSONified output for JSONP"""
@wraps(f)
def decorated_function(*args, **kwargs):
callback = request.args.get('callback', False)
if callback:
content = str(callback) + '(' + str(f().data) + ')'
return app.response_class(content, mimetype='application/json')
else:
return f(*args, **kwargs)
return decorated_function
@app.route('/test')
def testClassifier():
text = request.args['text'] if request.args['text'] else ''
# TODO: strip out illegal CHARS
result = dict(prediction=0)
if text:
result['prediction'] = app.classifier.predictText(text)
return jsonify( result )
@app.route('/')
def askTheG():
return render_template('genius.html')
if __name__ == '__main__':
app.run(debug=True)