Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,15 @@ import os
|
|
3 |
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, ServiceContext
|
4 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# ✅ Use Hugging Face embedding model
|
7 |
embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
8 |
service_context = ServiceContext.from_defaults(embed_model=embed_model)
|
|
|
3 |
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, ServiceContext
|
4 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
5 |
|
6 |
+
|
7 |
+
# Access from Hugging Face secret
|
8 |
+
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
9 |
+
|
10 |
+
if openai_api_key:
|
11 |
+
os.environ["OPENAI_API_KEY"] = openai_api_key # optional if your library reads it directly
|
12 |
+
else:
|
13 |
+
raise ValueError("❌ OPENAI_API_KEY not found. Add it in Space settings > Secrets.")
|
14 |
+
|
15 |
# ✅ Use Hugging Face embedding model
|
16 |
embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
17 |
service_context = ServiceContext.from_defaults(embed_model=embed_model)
|