Spaces:
Sleeping
Sleeping
| """ | |
| Utility functions for device detection, GPU listing, and HTML file reading for the web | |
| UI. | |
| These functions help in determining available devices for model inference, listing GPU | |
| names, and reading HTML content for the UI. | |
| """ | |
| from pathlib import Path | |
| from sentence_transformers import SentenceTransformer | |
| def open_html(file: str | Path) -> str: | |
| """ | |
| Reads and returns the content of an HTML file. | |
| Args: | |
| file (str | Path): Path to the HTML file (str or Path). | |
| Returns: | |
| str: The content of the HTML file as a string. | |
| """ | |
| content = "" | |
| with open(file, "r", encoding="utf-8") as f: | |
| content = f.read() | |
| return content | |
| def create_model_pools(name_list: list[str]) -> dict[str, SentenceTransformer]: | |
| """ | |
| Creates a pool of SentenceTransformer models based on the provided model names. | |
| Args: | |
| name_list (list[str]): List of model names to create SentenceTransformer | |
| instances. | |
| Returns: | |
| dict[str, SentenceTransformer]: A dictionary mapping model names to their | |
| corresponding SentenceTransformer instances. | |
| """ | |
| model_pool: dict[str, SentenceTransformer] = {} | |
| for name in name_list: | |
| model_pool[name] = SentenceTransformer(name) | |
| return model_pool | |