alessandro trinca tornidor commited on
Commit
224f2bb
·
1 Parent(s): e964313

chore: improve error logs in case of spacy model not found

Browse files
Files changed (1) hide show
  1. my_ghost_writer/text_parsers2.py +7 -3
my_ghost_writer/text_parsers2.py CHANGED
@@ -16,14 +16,15 @@ from my_ghost_writer.type_hints import SynonymInfo, WordSynonymResult, ContextIn
16
  custom_synonyms: dict[str, list[str]] = {}
17
  custom_synonym_handler = CustomSynonymHandler()
18
  # Load spaCy model
 
19
  try:
20
  nlp = spacy.load(SPACY_MODEL_NAME)
21
  app_logger.info(f"spacy model {SPACY_MODEL_NAME} has type:'{type(nlp)}'")
22
- except OSError:
 
23
  app_logger.error(
24
- f"spaCy model '{SPACY_MODEL_NAME}' not found. Please install it with: -python -m spacy download {SPACY_MODEL_NAME}'"
25
  )
26
- nlp = None
27
 
28
  # Ensure NLTK data is downloaded
29
  try:
@@ -45,6 +46,9 @@ def find_synonyms_for_phrase(text: str, start_idx: int, end_idx: int) -> list[Wo
45
  and returns a list of synonym results for each.
46
  """
47
  if nlp is None:
 
 
 
48
  raise HTTPException(status_code=503, detail="NLP service is unavailable")
49
 
50
  doc = nlp(text)
 
16
  custom_synonyms: dict[str, list[str]] = {}
17
  custom_synonym_handler = CustomSynonymHandler()
18
  # Load spaCy model
19
+ nlp = None
20
  try:
21
  nlp = spacy.load(SPACY_MODEL_NAME)
22
  app_logger.info(f"spacy model {SPACY_MODEL_NAME} has type:'{type(nlp)}'")
23
+ except (OSError, IOError) as ex:
24
+ app_logger.error(ex)
25
  app_logger.error(
26
+ f"spaCy model '{SPACY_MODEL_NAME}' not found. Please install it with: 'python -m spacy download {SPACY_MODEL_NAME}'"
27
  )
 
28
 
29
  # Ensure NLTK data is downloaded
30
  try:
 
46
  and returns a list of synonym results for each.
47
  """
48
  if nlp is None:
49
+ app_logger.error(
50
+ f"spaCy model '{SPACY_MODEL_NAME}' not found. Please install it with: 'python -m spacy download {SPACY_MODEL_NAME}'"
51
+ )
52
  raise HTTPException(status_code=503, detail="NLP service is unavailable")
53
 
54
  doc = nlp(text)