Spaces:
Sleeping
Sleeping
Ayush Rai
commited on
Commit
·
c71948c
1
Parent(s):
3372524
Fix HF cache dir and embedding model to avoid /data permission errors
Browse files- agent_startup.py +9 -3
agent_startup.py
CHANGED
|
@@ -2,10 +2,10 @@ import os
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
load_dotenv()
|
| 4 |
|
| 5 |
-
# Optionally write Google SA JSON (secret) to /
|
| 6 |
sa_json = os.getenv("GOOGLE_SERVICE_ACCOUNT_JSON")
|
| 7 |
if sa_json:
|
| 8 |
-
sa_path = "/
|
| 9 |
if not os.path.exists(sa_path):
|
| 10 |
with open(sa_path, "w", encoding="utf-8") as f:
|
| 11 |
f.write(sa_json)
|
|
@@ -17,11 +17,17 @@ from langchain_chroma import Chroma
|
|
| 17 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 18 |
from langchain_community.document_loaders import PyMuPDFLoader
|
| 19 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
print("loading embedding")
|
| 22 |
embedding_model = HuggingFaceEmbeddings(
|
| 23 |
model_name="sentence-transformers/paraphrase-MiniLM-L3-v2",
|
| 24 |
-
model_kwargs={'device': "cpu"}
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
persist_dir = os.getenv("PERSIST_DIR", "/data/chroma_db")
|
|
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
load_dotenv()
|
| 4 |
|
| 5 |
+
# Optionally write Google SA JSON (secret) to /tmp/sa.json for Gemini auth
|
| 6 |
sa_json = os.getenv("GOOGLE_SERVICE_ACCOUNT_JSON")
|
| 7 |
if sa_json:
|
| 8 |
+
sa_path = "/tmp/sa.json" # changed from /data to /tmp
|
| 9 |
if not os.path.exists(sa_path):
|
| 10 |
with open(sa_path, "w", encoding="utf-8") as f:
|
| 11 |
f.write(sa_json)
|
|
|
|
| 17 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 18 |
from langchain_community.document_loaders import PyMuPDFLoader
|
| 19 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 20 |
+
import os
|
| 21 |
+
|
| 22 |
+
# Force Hugging Face to use a writable cache directory
|
| 23 |
+
os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_cache"
|
| 24 |
+
os.environ["HF_HOME"] = "/tmp/hf_home"
|
| 25 |
|
| 26 |
print("loading embedding")
|
| 27 |
embedding_model = HuggingFaceEmbeddings(
|
| 28 |
model_name="sentence-transformers/paraphrase-MiniLM-L3-v2",
|
| 29 |
+
model_kwargs={'device': "cpu"},
|
| 30 |
+
cache_folder="/tmp/hf_cache"
|
| 31 |
)
|
| 32 |
|
| 33 |
persist_dir = os.getenv("PERSIST_DIR", "/data/chroma_db")
|