File size: 2,288 Bytes
c7b379a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import traceback
from i18n.i18n import I18nAuto
from datetime import datetime
import torch

from .hash import model_hash_ckpt, hash_id, hash_similarity

i18n = I18nAuto()


def show_model_info(cpt, show_long_id=False):
    try:
        h = model_hash_ckpt(cpt)
        id = hash_id(h)
        idread = cpt.get("id", "None")
        hread = cpt.get("hash", "None")
        if id != idread:
            id += (
                "("
                + i18n("Actually calculated")
                + "), "
                + idread
                + "("
                + i18n("Read from model")
                + ")"
            )
        sim = hash_similarity(h, hread)
        if not isinstance(sim, str):
            sim = "%.2f%%" % (sim * 100)
        if not show_long_id:
            h = i18n("Hidden")
            if h != hread:
                h = i18n("Similarity") + " " + sim + " -> " + h
        elif h != hread:
            h = (
                i18n("Similarity")
                + " "
                + sim
                + " -> "
                + h
                + "("
                + i18n("Actually calculated")
                + "), "
                + hread
                + "("
                + i18n("Read from model")
                + ")"
            )
        txt = f"""{i18n("Model name")}: %s
{i18n("Sealing date")}: %s
{i18n("Model Author")}: %s
{i18n("Information")}: %s
{i18n("Sampling rate")}: %s
{i18n("Pitch guidance (f0)")}: %s
{i18n("Version")}: %s
{i18n("ID(short)")}: %s
{i18n("ID(long)")}: %s""" % (
            cpt.get("name", i18n("Unknown")),
            datetime.fromtimestamp(float(cpt.get("timestamp", 0))),
            cpt.get("author", i18n("Unknown")),
            cpt.get("info", i18n("None")),
            cpt.get("sr", i18n("Unknown")),
            i18n("Exist") if cpt.get("f0", 0) == 1 else i18n("Not exist"),
            cpt.get("version", i18n("None")),
            id,
            h,
        )
    except:
        txt = traceback.format_exc()

    return txt


def show_info(path):
    try:
        if hasattr(path, "name"):
            path = path.name
        a = torch.load(path, map_location="cpu")
        txt = show_model_info(a, show_long_id=True)
        del a
    except:
        txt = traceback.format_exc()

    return txt