From 6790ff28eca66398d262e04d52773a64517adec0 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 8 Nov 2024 12:26:16 -0500 Subject: [PATCH] Update cli.py to ensure the required spaCy model is downloaded --- simplechat/cli.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/simplechat/cli.py b/simplechat/cli.py index 97c28de..2699727 100644 --- a/simplechat/cli.py +++ b/simplechat/cli.py @@ -1,9 +1,31 @@ import docopt import re +import sys +import subprocess + +import spacy +from spacy.cli import download + + +def ensure_spacy_model(): + """Ensure the required spaCy model is downloaded.""" + model_name = "en_core_web_sm" + try: + spacy.load(model_name) + except OSError: + console.print(f"Downloading required language model: {model_name}") + download(model_name) + console.print("Download complete!") + + +from rich.console import Console + +console = Console() +ensure_spacy_model() import xerox import simplemind as sm -from rich.console import Console + from rich.panel import Panel from prompt_toolkit import PromptSession from prompt_toolkit.styles import Style @@ -40,8 +62,6 @@ Options: --model= Specific model to use (e.g. o1-preview) """ -console = Console() - class Simplechat: def __init__(self):