Spaces:
Sleeping
Sleeping
Download chroma_utils_old.py from prithvi55/talk2data: direct link, hf CLI and curl.
- Browser
- Download file 736 Bytes
-
https://huggingface.co/spaces/prithvi55/talk2data/resolve/main/chroma_utils_old.py
- Command line
-
hf download hf://spaces/prithvi55/talk2data/chroma_utils_old.py
-
curl -L -o chroma_utils_old.py https://huggingface.co/spaces/prithvi55/talk2data/resolve/main/chroma_utils_old.py
736 Bytes
| import chromadb | |
| from chromadb.config import Settings | |
| from sentence_transformers import SentenceTransformer | |
| import torch | |
| import tempfile | |
| CHROMA_DIR = "chromadb_local" | |
| COLLECTION_NAME = "prompts" | |
| EMBEDDING_MODEL = "all-MiniLM-L6-v2" | |
| def get_chroma_client(): | |
| return chromadb.Client(Settings(persist_directory=CHROMA_DIR)) | |
| def get_chroma_collection(client): | |
| try: | |
| return client.get_collection(COLLECTION_NAME) | |
| except Exception: | |
| return client.create_collection(COLLECTION_NAME) | |
| def get_embedding_model(): | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| cache_dir = tempfile.mkdtemp() | |
| return SentenceTransformer(EMBEDDING_MODEL, device=device, cache_folder=cache_dir) | |