-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
32 lines (27 loc) · 864 Bytes
/
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
from flask import Flask, request
import spacy, explacy
from joblib import load
app = Flask(__name__)
modelFilename = "training/example.joblib"
#nlp_pl = spacy.load("pipelines/pl_core_news_sm")
nlp_en = spacy.load("pipelines/en_core_web_sm")
nlp = { "en":nlp_en}
clf = load(modelFilename)
@app.route("/api/ping")
def ping():
return "Pong!"
@app.route("/api/<string:lang>/analyze", methods = ['POST'])
def analyze(lang):
try:
text = request.form["s"]
explacy.print_parse_info(nlp[lang], text)
x_val = create_data({text}, "en")
y_val = clf.predict(x_val)
print(f"Prediction: {y_val}")
return ""
except Exception as ex:
print(ex)
return ""
def create_data(dataset, lang):
preprocessed_texts = list(nlp[lang].pipe(dataset))
return [string.vector for string in preprocessed_texts]