Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,9 +38,29 @@ app.config['MAX_CONTENT_LENGTH'] = 50 * 1024 * 1024 # 50MB limit
|
|
| 38 |
FAISS_INDEX_DIR = os.path.join(APP_ROOT, "faiss_indices")
|
| 39 |
EMBEDDING_DIM = 768 # all-mpnet-base-v2 embedding dimension
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
os.makedirs(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# Chunking Configuration
|
| 46 |
CHUNK_SIZE = 1000
|
|
|
|
| 38 |
FAISS_INDEX_DIR = os.path.join(APP_ROOT, "faiss_indices")
|
| 39 |
EMBEDDING_DIM = 768 # all-mpnet-base-v2 embedding dimension
|
| 40 |
|
| 41 |
+
def _ensure_writable_directory(path: str) -> str:
|
| 42 |
+
try:
|
| 43 |
+
os.makedirs(path, exist_ok=True)
|
| 44 |
+
test_file = os.path.join(path, '.write_test')
|
| 45 |
+
with open(test_file, 'w') as f:
|
| 46 |
+
f.write('ok')
|
| 47 |
+
os.remove(test_file)
|
| 48 |
+
return path
|
| 49 |
+
except Exception:
|
| 50 |
+
fallback = os.path.join('/tmp', os.path.basename(path))
|
| 51 |
+
os.makedirs(fallback, exist_ok=True)
|
| 52 |
+
try:
|
| 53 |
+
test_file = os.path.join(fallback, '.write_test')
|
| 54 |
+
with open(test_file, 'w') as f:
|
| 55 |
+
f.write('ok')
|
| 56 |
+
os.remove(test_file)
|
| 57 |
+
return fallback
|
| 58 |
+
except Exception:
|
| 59 |
+
return path
|
| 60 |
+
|
| 61 |
+
# Ensure writable directories exist when running under gunicorn, fallback to /tmp if needed
|
| 62 |
+
app.config['UPLOAD_FOLDER'] = _ensure_writable_directory(app.config['UPLOAD_FOLDER'])
|
| 63 |
+
FAISS_INDEX_DIR = _ensure_writable_directory(FAISS_INDEX_DIR)
|
| 64 |
|
| 65 |
# Chunking Configuration
|
| 66 |
CHUNK_SIZE = 1000
|