vasdevaman6 commited on
Commit
eb1e163
ยท
verified ยท
1 Parent(s): 46f882e

final fix

Browse files
Files changed (2) hide show
  1. Dockerfile +4 -4
  2. ocr_utils.py +10 -3
Dockerfile CHANGED
@@ -20,11 +20,11 @@ COPY requirements.txt .
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
  # ๐Ÿ›‘ CRITICAL FIX FOR EASYOCR PERMISSION: ๐Ÿ›‘
23
- # Create the necessary writable directory as root during the build process.
24
  # This prevents the application from crashing at runtime when the non-root user tries to create it.
25
- RUN mkdir -p /app/easyocr_models
26
  RUN chmod -R 777 /app/easyocr_models
27
- # NOTE: The chmod -R 777 /app fix you had is now replaced and refined by these two lines.
28
 
29
  # 3b. Copy the rest of your application code and models
30
  COPY . .
@@ -33,4 +33,4 @@ COPY . .
33
  ENV PORT 7860
34
 
35
  # Run the application using Gunicorn (the production web server)
36
- CMD exec gunicorn --bind 0.0.0.0:$PORT --workers 1 --threads 8 app:app
 
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
  # ๐Ÿ›‘ CRITICAL FIX FOR EASYOCR PERMISSION: ๐Ÿ›‘
23
+ # Create the necessary writable directories as root during the build process.
24
  # This prevents the application from crashing at runtime when the non-root user tries to create it.
25
+ RUN mkdir -p /app/easyocr_models/user_network
26
  RUN chmod -R 777 /app/easyocr_models
27
+ # NOTE: This ensures both model storage and user network directories are writable.
28
 
29
  # 3b. Copy the rest of your application code and models
30
  COPY . .
 
33
  ENV PORT 7860
34
 
35
  # Run the application using Gunicorn (the production web server)
36
+ CMD exec gunicorn --bind 0.0.0.0:$PORT --workers 1 --threads 8 app:app
ocr_utils.py CHANGED
@@ -6,13 +6,20 @@ import os
6
  # In ocr_utils.py
7
  # Set model_storage_directory to a folder inside your writable app directory (/app)
8
  # โš ๏ธ Use absolute path to prevent EasyOCR from defaulting to /.EasyOCR
9
- MODELS_DIR = "/app/easyocr_models" # <-- Changed to absolute path
 
10
  os.makedirs(MODELS_DIR, exist_ok=True) # Ensure the directory exists
 
11
 
12
- # DEBUG: Verify the directory
13
  print(f"[DEBUG] EasyOCR models directory: {MODELS_DIR}")
 
14
 
15
- reader = easyocr.Reader(['en'], model_storage_directory=MODELS_DIR)
 
 
 
 
16
 
17
  def extract_keywords_from_report(file_path):
18
  """
 
6
  # In ocr_utils.py
7
  # Set model_storage_directory to a folder inside your writable app directory (/app)
8
  # โš ๏ธ Use absolute path to prevent EasyOCR from defaulting to /.EasyOCR
9
+ MODELS_DIR = "/app/easyocr_models" # <-- Absolute path
10
+ USER_NETWORK_DIR = "/app/easyocr_models/user_network" # <-- Added to fix PermissionError
11
  os.makedirs(MODELS_DIR, exist_ok=True) # Ensure the directory exists
12
+ os.makedirs(USER_NETWORK_DIR, exist_ok=True) # Ensure the user network directory exists
13
 
14
+ # DEBUG: Verify the directories
15
  print(f"[DEBUG] EasyOCR models directory: {MODELS_DIR}")
16
+ print(f"[DEBUG] EasyOCR user network directory: {USER_NETWORK_DIR}")
17
 
18
+ reader = easyocr.Reader(
19
+ ['en'],
20
+ model_storage_directory=MODELS_DIR,
21
+ user_network_directory=USER_NETWORK_DIR
22
+ )
23
 
24
  def extract_keywords_from_report(file_path):
25
  """