glitz-dev commited on
Commit
2940309
·
1 Parent(s): 296015b

OpenCV log messages avoided

Browse files
Files changed (1) hide show
  1. hipaathesis.py +11 -6
hipaathesis.py CHANGED
@@ -27,6 +27,10 @@ def setup_cache_directories():
27
  def setup_nltk_data():
28
  """Setup NLTK data directory in container-writable location"""
29
  try:
 
 
 
 
30
  # Use the app directory for NLTK data in container
31
  nltk_data_dir = '/app/nltk_data'
32
 
@@ -56,11 +60,12 @@ def setup_nltk_data():
56
  try:
57
  nltk.data.find(f'tokenizers/{resource}' if 'punkt' in resource else f'corpora/{resource}')
58
  except LookupError:
59
- try:
60
- nltk.download(resource, download_dir=nltk_data_dir, quiet=True)
61
- print(f"Downloaded NLTK resource: {resource}")
62
- except Exception as e:
63
- print(f"Warning: Could not download {resource}: {e}")
 
64
 
65
  except Exception as e:
66
  print(f"Warning: NLTK setup failed: {e}")
@@ -103,7 +108,7 @@ try:
103
  import numpy as np
104
  OPENCV_AVAILABLE = True
105
  except ImportError:
106
- print("OpenCV not available. Using PIL for image preprocessing.")
107
  from PIL import Image
108
  OPENCV_AVAILABLE = False
109
 
 
27
  def setup_nltk_data():
28
  """Setup NLTK data directory in container-writable location"""
29
  try:
30
+ # Silence HuggingFace / Transformers logging
31
+ transformers.utils.logging.set_verbosity_error()
32
+ logging.getLogger("transformers").setLevel(logging.ERROR)
33
+
34
  # Use the app directory for NLTK data in container
35
  nltk_data_dir = '/app/nltk_data'
36
 
 
60
  try:
61
  nltk.data.find(f'tokenizers/{resource}' if 'punkt' in resource else f'corpora/{resource}')
62
  except LookupError:
63
+ with contextlib.redirect_stdout(None):
64
+ with contextlib.redirect_stderr(None):
65
+ try:
66
+ nltk.download(resource, download_dir=nltk_data_dir, quiet=True)
67
+ except:
68
+ pass # completely silent fallback
69
 
70
  except Exception as e:
71
  print(f"Warning: NLTK setup failed: {e}")
 
108
  import numpy as np
109
  OPENCV_AVAILABLE = True
110
  except ImportError:
111
+ # print("OpenCV not available. Using PIL for image preprocessing.")
112
  from PIL import Image
113
  OPENCV_AVAILABLE = False
114