-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrasa_api.py
29 lines (26 loc) · 1000 Bytes
/
rasa_api.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
def call():
from rasa_nlu.training_data import load_data
from rasa_nlu import config
from rasa_nlu.components import ComponentBuilder
from rasa_nlu.model import Trainer
builder = ComponentBuilder(use_cache=True)
training_data = load_data('./rasa_nlu_api/dataset.json')
trainer = Trainer(config.load("./rasa_nlu_api/config_pipeline.yml"), builder)
trainer.train(training_data)
model_directory = trainer.persist('./rasa_nlu_api/', fixed_model_name="model")
print('done')
return model_directory
# call()
def call_for(message):
# from datetime import datetime
# s = datetime.now()
from rasa_nlu.model import Interpreter
interpreter = Interpreter.load('rasa_nlu_api/default/model')
# from random import choice
# from json import loads
import spacy
nlp = spacy.load('./en')
parsed_sentence = interpreter.parse(message)
return parsed_sentence
# print(datetime.now()-s)
# print(call_for('fuck off')['intent']['name'])