-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
101 lines (80 loc) · 3 KB
/
server.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
# coding: utf-8
#
# Copyright (c) 2015, PAL Team.
# All rights reserved. See LICENSE for details.
import logging
from logging import Formatter
from flask import Blueprint
from flask import Flask
from flask import redirect
from flask import render_template
from flask.ext.restful import Api
from flask_restful_swagger import swagger
from pal.engine import Engine
from pal.validator import Validator
from pal.nlp.standard_nlp import StandardNLP
from pal.nlp.feature_extractor import FeatureExtractor
from pal.classifier import Classifier
from pal.executor import Executor
from pal.nlp.keyword_finder import KeywordFinder
from pal.nlp.noun_finder import NounFinder
from pal.nlp.question_classifier import QuestionClassifier
from pal.nlp.question_detector import QuestionDetector
from pal.nlp.tense_classifier import TenseClassifier
app = Flask(__name__)
app.config['DEBUG'] = True
pal_blueprint = Blueprint('pal_blueprint', __name__)
api_pal = swagger.docs(Api(pal_blueprint), apiVersion='0.1',
basePath='http://localhost:5000',
resourcePath='/',
produces=["application/json", "text/html"],
api_spec_url='/spec')
api_pal.add_resource(Engine, '/pal')
api_pal.add_resource(Validator, '/validate')
api_pal.add_resource(StandardNLP, '/standard_nlp')
api_pal.add_resource(FeatureExtractor, '/features')
api_pal.add_resource(Classifier, '/classify')
api_pal.add_resource(Executor, '/execute')
api_pal.add_resource(KeywordFinder, '/features/keywords')
api_pal.add_resource(NounFinder, '/features/nouns')
api_pal.add_resource(QuestionClassifier, '/features/qtype')
api_pal.add_resource(QuestionDetector, '/features/is_question')
api_pal.add_resource(TenseClassifier, '/features/tense')
@app.route('/docs')
def docs():
return redirect('/api/spec.html')
@app.route('/')
def index():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/debug')
def debug():
return render_template('debug.html')
# main doesn't run in wsgi
app.register_blueprint(pal_blueprint, url_prefix='/api')
# configure logging for pal engine
logger = logging.getLogger('PAL Engine')
logger.setLevel(logging.DEBUG)
if __name__ == '__main__':
file_handler = logging.FileHandler('flask_pal.log')
else:
# if being run on the server, use different file
file_handler = logging.FileHandler('/var/www/pal/flask_pal.log')
file_handler.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
# formatter only supports %s formatting
formatter = Formatter('%(asctime)s - %(name)s %(levelname)s:\n'
' [in %(pathname)s:%(lineno)d]\n'
' %(message)s\n'
'----')
ch.setFormatter(formatter)
file_handler.setFormatter(formatter)
logger.addHandler(ch)
logger.addHandler(file_handler)
if __name__ == '__main__':
# app.register_blueprint(pal_blueprint, url_prefix='/api')
app.run(debug=True, host='0.0.0.0')