File size: 1,584 Bytes
d66a6a3
 
 
 
 
 
79bb0de
8174ae1
 
79bb0de
8174ae1
 
 
 
 
 
 
79bb0de
 
8174ae1
9b36a13
 
d66a6a3
79bb0de
056eba8
 
b2443f5
9b36a13
b2443f5
 
 
 
 
2a860f6
b98f07f
056eba8
d66a6a3
056eba8
 
b98f07f
d66a6a3
056eba8
 
b98f07f
d66a6a3
b98f07f
 
 
d66a6a3
c85dcc4
b98f07f
 
d66a6a3
 
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
46
47
48
49
50
51
52
53
54
55
import typing

if typing.TYPE_CHECKING:
    import pandas as pd


# This should be one line, but written in multiple lines for readability
MODEL_HYPERLINK_TEMPLATE = " ".join([
    line.strip()
    for line in """
    <a
        target="_blank"
        href="{link}"
        style="color: var(--link-text-color); text-decoration: underline; text-decoration-style: dotted;"
    >
        {model_name}
    </a>
    """.strip().splitlines()
    if line.strip()
])


def model_hyperlink(link: str, model_name: str) -> str:
    return MODEL_HYPERLINK_TEMPLATE.format(link=link, model_name=model_name)


def make_clickable_model(model_name: str, link: str | None = None) -> str:
    org, _, model = model_name.rpartition("/")
    if not link:
        if not org:
            # Not a full model name, cannot be clicked
            return model_name
        link = f"https://huggingface.co/{org}/{model}"
    return model_hyperlink(link, model_name)


def styled_error(error: str) -> str:
    return f"<p style='color: red; font-size: 20px; text-align: center;'>{error}</p>"


def styled_warning(warn: str) -> str:
    return f"<p style='color: orange; font-size: 20px; text-align: center;'>{warn}</p>"


def styled_message(message: str) -> str:
    return f"<p style='color: green; font-size: 20px; text-align: center;'>{message}</p>"


def has_no_nan_values(df: "pd.DataFrame", columns: list[str]) -> "pd.Series":
    return df.loc[:, columns].notna().any(axis=1)


def has_nan_values(df: "pd.DataFrame", columns: list[str]) -> "pd.Series":
    return df.loc[:, columns].isna().any(axis=1)