Spaces:
Sleeping
Sleeping
Commit
·
5a08ed8
1
Parent(s):
ca54b04
Add environment variable configuration and directory creation for ML libraries
Browse files- Introduced environment variables for TORCH_HOME, TENSORFLOW_HOME, and KERAS_HOME to manage library directories.
- Implemented robust directory creation with error handling and fallback mechanisms to ensure stability.
- Enhanced logging to provide feedback on directory creation processes and any encountered issues.
- Dockerfile +5 -2
- src/streamlit_app.py +23 -0
Dockerfile
CHANGED
@@ -10,7 +10,7 @@ RUN apt-get update && apt-get install -y \
|
|
10 |
&& rm -rf /var/lib/apt/lists/*
|
11 |
|
12 |
# Create necessary directories with proper permissions
|
13 |
-
RUN mkdir -p /app/.streamlit /tmp/docling_temp /tmp/easyocr_models /tmp/cache /tmp/config /tmp/data /tmp/huggingface /tmp/huggingface_cache /tmp/transformers_cache /tmp/datasets_cache && \
|
14 |
chmod 755 /app/.streamlit && \
|
15 |
chmod 777 /tmp/docling_temp && \
|
16 |
chmod 777 /tmp/easyocr_models && \
|
@@ -20,7 +20,10 @@ RUN mkdir -p /app/.streamlit /tmp/docling_temp /tmp/easyocr_models /tmp/cache /t
|
|
20 |
chmod 777 /tmp/huggingface && \
|
21 |
chmod 777 /tmp/huggingface_cache && \
|
22 |
chmod 777 /tmp/transformers_cache && \
|
23 |
-
chmod 777 /tmp/datasets_cache
|
|
|
|
|
|
|
24 |
|
25 |
COPY requirements.txt ./
|
26 |
COPY src/ ./src/
|
|
|
10 |
&& rm -rf /var/lib/apt/lists/*
|
11 |
|
12 |
# Create necessary directories with proper permissions
|
13 |
+
RUN mkdir -p /app/.streamlit /tmp/docling_temp /tmp/easyocr_models /tmp/cache /tmp/config /tmp/data /tmp/huggingface /tmp/huggingface_cache /tmp/transformers_cache /tmp/datasets_cache /tmp/torch /tmp/tensorflow /tmp/keras && \
|
14 |
chmod 755 /app/.streamlit && \
|
15 |
chmod 777 /tmp/docling_temp && \
|
16 |
chmod 777 /tmp/easyocr_models && \
|
|
|
20 |
chmod 777 /tmp/huggingface && \
|
21 |
chmod 777 /tmp/huggingface_cache && \
|
22 |
chmod 777 /tmp/transformers_cache && \
|
23 |
+
chmod 777 /tmp/datasets_cache && \
|
24 |
+
chmod 777 /tmp/torch && \
|
25 |
+
chmod 777 /tmp/tensorflow && \
|
26 |
+
chmod 777 /tmp/keras
|
27 |
|
28 |
COPY requirements.txt ./
|
29 |
COPY src/ ./src/
|
src/streamlit_app.py
CHANGED
@@ -120,6 +120,29 @@ for env_var in hf_dirs:
|
|
120 |
except Exception as e2:
|
121 |
logging.error(f"Failed to create fallback Hugging Face directory for {env_var}: {e2}")
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
# Log startup information
|
124 |
logging.info("=" * 50)
|
125 |
logging.info("Docling Streamlit App Starting")
|
|
|
120 |
except Exception as e2:
|
121 |
logging.error(f"Failed to create fallback Hugging Face directory for {env_var}: {e2}")
|
122 |
|
123 |
+
# Additional environment variables for other libraries that might access root directories
|
124 |
+
os.environ['TORCH_HOME'] = os.path.join(TEMP_DIR, 'torch')
|
125 |
+
os.environ['TENSORFLOW_HOME'] = os.path.join(TEMP_DIR, 'tensorflow')
|
126 |
+
os.environ['KERAS_HOME'] = os.path.join(TEMP_DIR, 'keras')
|
127 |
+
os.environ['MLFLOW_TRACKING_URI'] = 'file:' + os.path.join(TEMP_DIR, 'mlruns')
|
128 |
+
|
129 |
+
# Create additional library directories
|
130 |
+
lib_dirs = ['TORCH_HOME', 'TENSORFLOW_HOME', 'KERAS_HOME']
|
131 |
+
for env_var in lib_dirs:
|
132 |
+
try:
|
133 |
+
os.makedirs(os.environ[env_var], exist_ok=True)
|
134 |
+
logging.info(f"Created library directory for {env_var}: {os.environ[env_var]}")
|
135 |
+
except Exception as e:
|
136 |
+
logging.warning(f"Could not create library directory for {env_var}: {e}")
|
137 |
+
# Fallback to /tmp
|
138 |
+
fallback_path = os.path.join('/tmp', env_var.lower())
|
139 |
+
os.environ[env_var] = fallback_path
|
140 |
+
try:
|
141 |
+
os.makedirs(fallback_path, exist_ok=True)
|
142 |
+
logging.info(f"Using fallback library directory for {env_var}: {fallback_path}")
|
143 |
+
except Exception as e2:
|
144 |
+
logging.error(f"Failed to create fallback library directory for {env_var}: {e2}")
|
145 |
+
|
146 |
# Log startup information
|
147 |
logging.info("=" * 50)
|
148 |
logging.info("Docling Streamlit App Starting")
|