final fix
Browse files- Dockerfile +4 -4
- 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
|
| 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:
|
| 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" # <--
|
|
|
|
| 10 |
os.makedirs(MODELS_DIR, exist_ok=True) # Ensure the directory exists
|
|
|
|
| 11 |
|
| 12 |
-
# DEBUG: Verify the
|
| 13 |
print(f"[DEBUG] EasyOCR models directory: {MODELS_DIR}")
|
|
|
|
| 14 |
|
| 15 |
-
reader = easyocr.Reader(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
"""
|