Spaces:
Sleeping
Sleeping
Commit ·
1798510
1
Parent(s): 28acaaf
Critical fixes for Docker deployment
Browse files1. Fixed cache directory permissions:
- Added cache directory setup in Dockerfile with proper permissions
- Added HF_HOME and TRANSFORMERS_CACHE environment variables
- Added cache directory initialization in app startup
2. Fixed type annotation compatibility:
- Removed @st .cache_resource decorators from class methods
- Fixed Python 3.9 compatibility issues with union types
- Updated TranslationService and ABSAProcessor model loading
These fixes should resolve the permission denied and type annotation errors.
- Dockerfile +5 -0
- app_enhanced.py +27 -0
- src/utils/data_processor.py +5 -7
Dockerfile
CHANGED
|
@@ -9,6 +9,11 @@ RUN apt-get update && apt-get install -y \
|
|
| 9 |
git \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Copy requirements first for better caching
|
| 13 |
COPY requirements-docker.txt ./requirements.txt
|
| 14 |
|
|
|
|
| 9 |
git \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
+
# Create cache directory with proper permissions
|
| 13 |
+
RUN mkdir -p /.cache && chmod 777 /.cache
|
| 14 |
+
ENV HF_HOME=/.cache/huggingface
|
| 15 |
+
ENV TRANSFORMERS_CACHE=/.cache/huggingface/transformers
|
| 16 |
+
|
| 17 |
# Copy requirements first for better caching
|
| 18 |
COPY requirements-docker.txt ./requirements.txt
|
| 19 |
|
app_enhanced.py
CHANGED
|
@@ -8,6 +8,33 @@ import pandas as pd
|
|
| 8 |
import sys
|
| 9 |
import os
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Add src directory to path for imports
|
| 12 |
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
| 13 |
|
|
|
|
| 8 |
import sys
|
| 9 |
import os
|
| 10 |
|
| 11 |
+
# Setup cache directories for Docker environment
|
| 12 |
+
def setup_cache_directories():
|
| 13 |
+
"""Setup cache directories with proper permissions for containerized environment."""
|
| 14 |
+
cache_dirs = [
|
| 15 |
+
os.path.expanduser("~/.cache"),
|
| 16 |
+
os.path.expanduser("~/.cache/huggingface"),
|
| 17 |
+
os.path.expanduser("~/.cache/huggingface/transformers"),
|
| 18 |
+
"/.cache",
|
| 19 |
+
"/.cache/huggingface",
|
| 20 |
+
"/.cache/huggingface/transformers"
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
for cache_dir in cache_dirs:
|
| 24 |
+
try:
|
| 25 |
+
os.makedirs(cache_dir, exist_ok=True)
|
| 26 |
+
# Try to create a test file to check write permissions
|
| 27 |
+
test_file = os.path.join(cache_dir, "test_write.tmp")
|
| 28 |
+
with open(test_file, 'w') as f:
|
| 29 |
+
f.write("test")
|
| 30 |
+
os.remove(test_file)
|
| 31 |
+
except (PermissionError, OSError):
|
| 32 |
+
# If we can't write to this directory, continue with others
|
| 33 |
+
continue
|
| 34 |
+
|
| 35 |
+
# Setup cache directories at startup
|
| 36 |
+
setup_cache_directories()
|
| 37 |
+
|
| 38 |
# Add src directory to path for imports
|
| 39 |
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
| 40 |
|
src/utils/data_processor.py
CHANGED
|
@@ -86,15 +86,14 @@ class TranslationService:
|
|
| 86 |
self.tokenizer = None
|
| 87 |
self._load_model()
|
| 88 |
|
| 89 |
-
|
| 90 |
-
def _load_model(_self):
|
| 91 |
"""Load M2M100 model for translation."""
|
| 92 |
try:
|
| 93 |
from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
|
| 94 |
|
| 95 |
model_name = "facebook/m2m100_418M"
|
| 96 |
-
|
| 97 |
-
|
| 98 |
|
| 99 |
logger.info("Translation model loaded successfully")
|
| 100 |
except Exception as e:
|
|
@@ -180,13 +179,12 @@ class ABSAProcessor:
|
|
| 180 |
self.aspect_extractor = None
|
| 181 |
self._load_model()
|
| 182 |
|
| 183 |
-
|
| 184 |
-
def _load_model(_self):
|
| 185 |
"""Load pyABSA model."""
|
| 186 |
try:
|
| 187 |
from pyabsa import ATEPCCheckpointManager
|
| 188 |
|
| 189 |
-
|
| 190 |
checkpoint='multilingual',
|
| 191 |
auto_device=True,
|
| 192 |
task_code='ATEPC'
|
|
|
|
| 86 |
self.tokenizer = None
|
| 87 |
self._load_model()
|
| 88 |
|
| 89 |
+
def _load_model(self):
|
|
|
|
| 90 |
"""Load M2M100 model for translation."""
|
| 91 |
try:
|
| 92 |
from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
|
| 93 |
|
| 94 |
model_name = "facebook/m2m100_418M"
|
| 95 |
+
self.tokenizer = M2M100Tokenizer.from_pretrained(model_name)
|
| 96 |
+
self.model = M2M100ForConditionalGeneration.from_pretrained(model_name)
|
| 97 |
|
| 98 |
logger.info("Translation model loaded successfully")
|
| 99 |
except Exception as e:
|
|
|
|
| 179 |
self.aspect_extractor = None
|
| 180 |
self._load_model()
|
| 181 |
|
| 182 |
+
def _load_model(self):
|
|
|
|
| 183 |
"""Load pyABSA model."""
|
| 184 |
try:
|
| 185 |
from pyabsa import ATEPCCheckpointManager
|
| 186 |
|
| 187 |
+
self.aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(
|
| 188 |
checkpoint='multilingual',
|
| 189 |
auto_device=True,
|
| 190 |
task_code='ATEPC'
|