-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarize-demo.py
executable file
·58 lines (47 loc) · 1.36 KB
/
summarize-demo.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
#!/usr/bin/env python
from bottle import Bottle, request, view
from summarize import summarize
DEMO_TEXT = (
"Alice and Bob are friends. Alice is fun and cuddly. Bob is cute and"
" quirky. Together they go on wonderful adventures in the land of"
" tomorrow. Alice's cuddliness and Bob's cuteness allow them to reach"
" their goals. But before they get to them, they have to go past their"
" mortal enemy — Mr. Boredom. He is ugly and mean. They will surely"
" defeat him. He is no match for their abilities."
)
LANGUAGES = (
'danish',
'dutch',
'english',
'finnish',
'french',
'german',
'italian',
'norwegian',
'portuguese',
'spanish',
'swedish',
)
app = Bottle()
@app.route('/', method='GET')
@app.route('/', method='POST')
@view('index')
def index():
text = request.forms.getunicode('text')
number = int_or_none(request.forms.get('number'))
language = request.forms.get('language') or 'english'
result = summarize(text, number, language) if number and text else None
return {
'text': text or DEMO_TEXT,
'result': result,
'number': number or 5,
'language': language,
'available_languages': LANGUAGES
}
def int_or_none(value):
try:
return int(value)
except TypeError:
return None
if __name__ == "__main__":
app.run()