ftshijt commited on
Commit
69da775
·
1 Parent(s): a1f943e

fix nltk access

Browse files
Files changed (2) hide show
  1. Dockerfile +6 -0
  2. app.py +15 -0
Dockerfile CHANGED
@@ -1,5 +1,7 @@
1
  FROM python:3.9-slim
2
 
 
 
3
  WORKDIR /app
4
 
5
  # Install system dependencies
@@ -47,5 +49,9 @@ RUN mkdir -m 777 /tmp/NUMBA_CACHE_DIR /tmp/MPLCONFIGDIR
47
  ENV NUMBA_CACHE_DIR=/tmp/NUMBA_CACHE_DIR/
48
  ENV MPLCONFIGDIR=/tmp/MPLCONFIGDIR/
49
 
 
 
 
 
50
  # Run the application
51
  CMD ["python", "app.py"]
 
1
  FROM python:3.9-slim
2
 
3
+ USER root
4
+
5
  WORKDIR /app
6
 
7
  # Install system dependencies
 
49
  ENV NUMBA_CACHE_DIR=/tmp/NUMBA_CACHE_DIR/
50
  ENV MPLCONFIGDIR=/tmp/MPLCONFIGDIR/
51
 
52
+ # Pre-download NLTK data
53
+ RUN python -m nltk.downloader -d /app/nltk_data punkt stopwords wordnet
54
+
55
+
56
  # Run the application
57
  CMD ["python", "app.py"]
app.py CHANGED
@@ -22,6 +22,21 @@ UPLOAD_DIR = os.path.join(DATA_DIR, "uploads")
22
  RESULTS_DIR = os.path.join(DATA_DIR, "results")
23
  CONFIG_DIR = os.path.join(DATA_DIR, "configs")
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  # Check if VERSA is installed
26
  def check_versa_installation():
27
  """Check if VERSA is properly installed"""
 
22
  RESULTS_DIR = os.path.join(DATA_DIR, "results")
23
  CONFIG_DIR = os.path.join(DATA_DIR, "configs")
24
 
25
+ # Set NLTK_DATA directory to a writable location within the container
26
+ os.environ["NLTK_DATA"] = "/app/nltk_data"
27
+ os.makedirs("/app/nltk_data", exist_ok=True)
28
+
29
+ # Pre-download NLTK data during startup
30
+ try:
31
+ import nltk
32
+ for package in ['punkt', 'stopwords', 'wordnet']:
33
+ try:
34
+ nltk.download(package, quiet=True, download_dir='/app/nltk_data')
35
+ except:
36
+ pass
37
+ except Exception as e:
38
+ print(f"Warning: NLTK setup failed: {e}")
39
+
40
  # Check if VERSA is installed
41
  def check_versa_installation():
42
  """Check if VERSA is properly installed"""