-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
74 lines (55 loc) · 2.51 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
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
"""
DELETE THIS MODULE STRING AND REPLACE IT WITH A DESCRIPTION OF YOUR APP.
app.py Template
The app.py script does several things:
- import the necessary code
- create a subclass of ClamsApp that defines the metadata and provides a method to run the wrapped NLP tool
- provide a way to run the code as a RESTful Flask service
"""
import argparse
import logging
# Imports needed for Clams and MMIF.
# Non-NLP Clams applications will require AnnotationTypes
from clams import ClamsApp, Restifier
from mmif import Mmif, View, Annotation, Document, AnnotationTypes, DocumentTypes
# For an NLP tool we need to import the LAPPS vocabulary items
from lapps.discriminators import Uri
class TextSummarizer(ClamsApp):
def __init__(self):
super().__init__()
def _appmetadata(self):
# see https://sdk.clams.ai/autodoc/clams.app.html#clams.app.ClamsApp._load_appmetadata
# Also check out ``metadata.py`` in this directory.
# When using the ``metadata.py`` leave this do-nothing "pass" method here.
pass
def _annotate(self, mmif: Mmif, **parameters) -> Mmif:
# see https://sdk.clams.ai/autodoc/clams.app.html#clams.app.ClamsApp._annotate
raise NotImplementedError
def get_app():
"""
This function effectively creates an instance of the app class, without any arguments passed in, meaning, any
external information such as initial app configuration should be set without using function arguments. The easiest
way to do this is to set global variables before calling this.
"""
# for example:
# return TextSummarizer(create, from, global, params)
raise NotImplementedError
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--port", action="store", default="5000", help="set port to listen")
parser.add_argument("--production", action="store_true", help="run gunicorn server")
# add more arguments as needed
# parser.add_argument(more_arg...)
parsed_args = parser.parse_args()
# create the app instance
# if get_app() call requires any "configurations", they should be set now as global variables
# and referenced in the get_app() function. NOTE THAT you should not change the signature of get_app()
app = get_app()
http_app = Restifier(app, port=int(parsed_args.port))
# for running the application in production mode
if parsed_args.production:
http_app.serve_production()
# development mode
else:
app.logger.setLevel(logging.DEBUG)
http_app.run()