-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
46 lines (32 loc) · 1.09 KB
/
server.py
File metadata and controls
46 lines (32 loc) · 1.09 KB
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
import logging
import json
import os
from dotenv import load_dotenv
from flask import Flask, render_template, request
from cliff.api import Cliff
VERSION = "2.6.1"
MAX_CHARS = 250 # limit the amount of text users can send in
load_dotenv() # set environment variables from .env file if available
app = Flask(__name__)
# setup logging
logging.basicConfig(level=logging.WARN)
log = logging.getLogger(__file__)
log.info("---------------------------------------------------------------------------")
# set up the api client we will use
CLIFF_URL = os.environ.get("CLIFF_URL", "http://localhost:8080")
cliff = Cliff(CLIFF_URL)
# render the homepage
@app.route("/")
def index():
return render_template('home.html', version=VERSION)
# return json results from CLIFF
@app.route("/process", methods=['POST'])
def geoparse():
text = request.form['text']
language = request.form['language']
demonyms = request.form['demonyms'] == 'true'
results = cliff.parse_text(text[0:MAX_CHARS], demonyms, language)
return json.dumps(results)
if __name__ == "__main__":
app.debug = True
app.run()