3

I made a bot using Rasa NLU and Rasa Core. It is connected to a Node.js server and React.js Front end. The way I run this python script is:

var PythonShell = require('python-shell');

var options = {
    mode: 'text',
    pythonOptions: ['-u'],
    scriptPath: './server/Rasa_Bot_Final'
};

var pyshell = new PythonShell('dialogue_management_model.py', options);


app.post('/message', (req, res) => {
    pyshell.on('message', function (message) {
        // received a message sent from the Python script (a simple "print" statement)
        res.end(message)
    });
    pyshell.send(req.body.messageFromUser);
})

This works on my localhost, however, when deploying to heroku, I get this error:

Error: OSError: [E050] Can't find model 'en'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.

This is because I am unable to run:

python -m spacy download en_core_web_md
python -m spacy link en_core_web_md en

on heroku.

Can someone please help me get around this?

I've referenced these: https://spacy.io/usage/

https://github.com/explosion/spaCy/issues/1099

2 Answers2

5

Make sure you added spacy in the requirements and a Procfile containing the python commands.

see: Doc for Procfile

In the Procfile:

web: python -m spacy download en_core_web_md && python -m spacy link en_core_web_md en

If it comes from the fact that no python code can be run then it may come from the dyno that is unable to recognize your code and setup everything accordingly.

You should check this, I think that's what heroku calls buildpack.

1

First, be sure that the name of your project and the name of your Heroku app match exactly.

The following has worked for me:

Requirements.txt

flask
click
gunicorn==19.9.0
requests==2.21.0
spacy==2.0.11
sklearn-crfsuite==0.3.6
rasa-nlu==0.13.2
rasa-core==0.11.1
rasa-core-sdk==0.11.0

=========================================================

Procfile (assuming you define your application, routes etc., in app.py

web gunicorn app:app setup.wsgi --log-file -

========================================================

Download the spaCy en model:

Login to your Heroku account then, in your terminal:

$ heroku run bash -a rec-bot
$ python -m spacy download en
GDB
  • 3,379
  • 2
  • 26
  • 38
  • 1
    The filesystem of heroky dynos is temporary. You can download files with that command, but they’ll be gone after a day! So it seems like one would need to deploy e.g. special commits that include the data files, or somehow customize spacy to look for its files in a storage service such as AWS S3 (like a typical setup for uploaded files for a heroku web app) – merwok May 10 '19 at 21:56