-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
33 lines (22 loc) · 742 Bytes
/
application.py
File metadata and controls
33 lines (22 loc) · 742 Bytes
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
from flair_as_service.text import Text
from flair_as_service import Configs, InitializedPipeline
configs = Configs("./conf/config.json")
if configs.mode == "server":
from sanic import Sanic
from sanic.response import json
raw_pipeline = configs.pipeline
pipeline = InitializedPipeline(raw_pipeline)
def make_text(sent):
return Text(sent, configs=configs, pipeline=pipeline)
if __name__ == "__main__":
app = Sanic()
@app.route("/")
async def process(request):
try:
in_text = request.json["text"]
except:
in_text = request.args["text"][0]
text = make_text(in_text)
text.analyze()
return json(text.results)
app.run(host="0.0.0.0", port=5000)