Spaces:
Running
Running
Refactor environment variable setup for cache and database paths in app initialization
Browse files- app.py +13 -0
- infrastructure/database.py +1 -1
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
from flask import Flask
|
| 2 |
from flask_cors import CORS
|
|
|
|
|
|
|
| 3 |
from infrastructure.logger import setup_logger
|
| 4 |
from routes.web import web_bp
|
| 5 |
from routes.api import api_bp
|
|
@@ -12,6 +14,17 @@ def create_app():
|
|
| 12 |
app = Flask(__name__, template_folder='static')
|
| 13 |
CORS(app)
|
| 14 |
app.config.from_object('config.Config')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
app.register_blueprint(web_bp)
|
| 17 |
app.register_blueprint(api_bp)
|
|
|
|
| 1 |
from flask import Flask
|
| 2 |
from flask_cors import CORS
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
from infrastructure.logger import setup_logger
|
| 6 |
from routes.web import web_bp
|
| 7 |
from routes.api import api_bp
|
|
|
|
| 14 |
app = Flask(__name__, template_folder='static')
|
| 15 |
CORS(app)
|
| 16 |
app.config.from_object('config.Config')
|
| 17 |
+
for k,v in {
|
| 18 |
+
"PERSIST_DIRECTORY": "/data/chroma_db",
|
| 19 |
+
"XDG_CACHE_HOME": "/data/.cache",
|
| 20 |
+
"HF_HOME": "/data/.cache/huggingface",
|
| 21 |
+
"HUGGINGFACE_HUB_CACHE": "/data/.cache/huggingface/hub",
|
| 22 |
+
"TRANSFORMERS_CACHE": "/data/.cache/hf",
|
| 23 |
+
"SENTENCE_TRANSFORMERS_HOME": "/data/.cache/sentence-transformers",
|
| 24 |
+
"HOME": "/data",
|
| 25 |
+
}.items():
|
| 26 |
+
os.environ.setdefault(k, v)
|
| 27 |
+
pathlib.Path(v).mkdir(parents=True, exist_ok=True)
|
| 28 |
|
| 29 |
app.register_blueprint(web_bp)
|
| 30 |
app.register_blueprint(api_bp)
|
infrastructure/database.py
CHANGED
|
@@ -61,7 +61,7 @@ def _init_chroma_client():
|
|
| 61 |
os.remove(test_file)
|
| 62 |
_logger.info(f"Initializing Chroma PersistentClient at {abs_path}")
|
| 63 |
import chromadb
|
| 64 |
-
return chromadb.PersistentClient(path=
|
| 65 |
except Exception as e: # pragma: no cover - environment specific
|
| 66 |
tried.append((cand, str(e)))
|
| 67 |
# Continue to next candidate
|
|
|
|
| 61 |
os.remove(test_file)
|
| 62 |
_logger.info(f"Initializing Chroma PersistentClient at {abs_path}")
|
| 63 |
import chromadb
|
| 64 |
+
return chromadb.PersistentClient(path=os.environ["PERSIST_DIRECTORY"])
|
| 65 |
except Exception as e: # pragma: no cover - environment specific
|
| 66 |
tried.append((cand, str(e)))
|
| 67 |
# Continue to next candidate
|