-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (35 loc) · 1.04 KB
/
main.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
from distutils.log import debug
from flask import Flask, jsonify, request
from flask_restful import Api, Resource
import spacy
import json
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
api = Api(app)
model = spacy.load('model-best')
class Modelo():
def get(frase):
labels = []
doc = model(frase).doc
for ent in doc.ents:
labels.append(ent.label_)
#print(ent)
#print(labels)
return labels
# ...
@app.route('/modelo', methods=['POST'])
def procesa_json():
content_type = request.headers.get('Content-Type')
#print("content_type: " + content_type)
#print("request.charset: " + request.charset)
if (content_type == 'application/json'):
#Acción
mensaje = request.json['mensaje']
analisis = Modelo.get(mensaje)
jeison = jsonify(analisis)
return jeison
return jsonify(datos)
else:
return 'Content-Type not supported!'
if __name__ == "__main__":
app.run(host='0.0.0.0')