import cherrypy
from rasa_nlu.config import RasaNLUConfig
from rasa_nlu.model import Interpreter
import nltk
import spacy
nlp = spacy.load("en_core_web_md")
interpreter = Interpreter.load("./model", RasaNLUConfig("config.json"))
server_config = {
'server.socket_host': '0.0.0.0',
'server.socket_port': 8071,
'tools.cors.on': True
}
class Api:
@cherrypy.expose
@cherrypy.tools.json_in() #get json
@cherrypy.tools.json_out() #return json
def get_entities(self):
data = cherrypy.request.json
print("data : ", data)
text = data["text"]
sentencs = nltk.sent_tokenize(text)
output = []
for sen in sentencs:
output.append(interpreter.parse(sen))
return output
# In[9]:
def cors():
if cherrypy.request.method == 'OPTIONS':
cherrypy.response.headers['Access-Control-Allow-Methods'] = 'POST'
cherrypy.response.headers[
'Access-Control-Allow-Headers'] = 'content-type'
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
return True
else:
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
# In[10]:
if __name__ == '__main__':
# noinspection PyProtectedMember
cherrypy.tools.cors = cherrypy._cptools.HandlerTool(cors)
cherrypy.config.update(server_config)
cherrypy.response.timeout = 1000000000
api = Api()
cherrypy.quickstart(api)
我得到的错误
我已将spacy模型加载到nlp变量中,但出现错误。我已经下载了语言模型。
第114行,在sure_proper_language_model中 引发Exception(“无法加载spacy语言模型。加载模型返回'None'。”) 例外:无法加载spacy语言模型。加载模型返回“无”。