File size: 1,283 Bytes
25c5a9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bec450e
25c5a9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
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