-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
73 lines (53 loc) · 2.17 KB
/
Copy pathapp.py
File metadata and controls
73 lines (53 loc) · 2.17 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
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
"""
Heuristic Chyron Understanding (prototype)
Converts chyron text from docTR/Tesseract/LLaVA MMIF output into a name and list of attributes.
"""
import argparse
import logging
from clams import ClamsApp, Restifier
from mmif import Mmif, DocumentTypes
import interpreter
class HeuristicChyronInterpreter(ClamsApp):
def __init__(self):
super().__init__()
# Currently no CUDA implementation.
def _appmetadata(self):
# using metadata.py
pass
def _annotate(self, mmif: Mmif, **parameters) -> Mmif:
self.mmif = mmif if isinstance(mmif, Mmif) else Mmif(mmif)
new_view = self.mmif.new_view()
self.sign_view(new_view, parameters)
new_view.new_contain(DocumentTypes.TextDocument)
for doc in self.mmif.get_documents_by_type(DocumentTypes.TextDocument):
self._run_interpreter(doc, new_view, not parameters.get('note4mode'))
return self.mmif
def _run_interpreter(self, doc, new_view, do_normalize):
"""
Run the chyron interpreter over the document and add annotations to the view.
"""
content = interpreter.split_text(doc.text_value, do_normalize)
mmif_vids = self.mmif.get_documents_by_type(DocumentTypes.VideoDocument)
vid_id = mmif_vids[0].long_id
out_doc = new_view.new_textdocument(text=content, document=vid_id, origin=doc.long_id, provenance='derived',
mime='application/json')
def get_app():
"""
Create an instance of the app class.
"""
return HeuristicChyronInterpreter()
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")
parsed_args = parser.parse_args()
# create the app instance
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()