From 3ab3fd547605c65b7831ae5569756e39ad81ba66 Mon Sep 17 00:00:00 2001 From: Xevion Date: Wed, 30 Mar 2022 02:10:20 -0500 Subject: [PATCH] Ensure Spacy NLP model is downloaded by Heroku in production --- app.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app.py b/app.py index f4416ec..b2d5599 100644 --- a/app.py +++ b/app.py @@ -11,6 +11,7 @@ from flask_login import LoginManager, current_user from flask_sqlalchemy import SQLAlchemy from werkzeug.security import generate_password_hash from database import db +import spacy csrf = CSRFProtect() @@ -26,6 +27,14 @@ def create_app(): # Heroku deployment if app.config['ENV'] == 'production': + # Deal with spacy model downloading + spacy_model = 'en_core_web_sm' + try: + spacy.load(spacy_model) + except: # If not present, we download + spacy.cli.download(spacy_model) + spacy.load(spacy_model) + app.config['SECRET_KEY'] = os.getenv('SECRET_KEY') app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', '').replace('postgres://', 'postgresql://', 1)