Download app/utils.py from Juslin/elim-api: direct link, hf CLI and curl.
- Browser
- Download file 630 Bytes
-
https://huggingface.co/spaces/Juslin/elim-api/resolve/main/app/utils.py
- Command line
-
hf download hf://spaces/Juslin/elim-api/app/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Juslin/elim-api/resolve/main/app/utils.py
630 Bytes
| from llama_index.core import VectorStoreIndex, Document | |
| from llama_index.core.settings import Settings | |
| from llama_index.embeddings.huggingface import HuggingFaceEmbedding | |
| import os | |
| CACHE_DIR = os.getenv("LLAMA_INDEX_CACHE_DIR", "/app/model_cache") | |
| embed_model = HuggingFaceEmbedding(model_name="all-MiniLM-L6-v2", cache_folder=CACHE_DIR) | |
| Settings.embed_model = embed_model | |
| Settings.llm = None | |
| def get_index_from_text(document_text: str): | |
| """ | |
| Builds an in-memory index from user input using local embeddings only. No LLM. | |
| """ | |
| doc = Document(text=document_text) | |
| return VectorStoreIndex.from_documents([doc]) | |