-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelmanager.cpp
More file actions
69 lines (60 loc) · 1.99 KB
/
Copy pathmodelmanager.cpp
File metadata and controls
69 lines (60 loc) · 1.99 KB
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
#include "modelmanager.h"
#include <QFileInfo>
#include <QStandardPaths>
namespace {
const char* kDefaultModel = "ggml-base.en.bin";
const char* kBaseUrl = "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/";
// Download catalog. base.en carries its authoritative checksum/size; the others
// have empty sha256 (checksum skipped) until their values are filled in — see the
// note below. Order matters: the default model is listed first.
//
// TODO: populate the tiny.en and base (multilingual) sha256/size from the
// canonical HuggingFace LFS pointers so those downloads are checksum-verified too.
QList<ModelInfo> makeCatalog()
{
return {
{ "ggml-base.en.bin", "Base — English (default)",
QString(kBaseUrl) + "ggml-base.en.bin",
"a03779c86df3323075f5e796cb2ce5029f00ec8869eee3fdfb897afe36c6d002",
147964211, false },
{ "ggml-tiny.en.bin", "Tiny — English (fastest)",
QString(kBaseUrl) + "ggml-tiny.en.bin",
QString(), 0, false },
{ "ggml-base.bin", "Base — multilingual",
QString(kBaseUrl) + "ggml-base.bin",
QString(), 0, true },
};
}
} // namespace
QString ModelManager::defaultModelName()
{
return QString::fromLatin1(kDefaultModel);
}
QList<ModelInfo> ModelManager::catalog()
{
return makeCatalog();
}
ModelInfo ModelManager::modelInfo(const QString& name)
{
const QList<ModelInfo> all = makeCatalog();
for (const ModelInfo& m : all) {
if (m.name == name)
return m;
}
return all.first(); // default
}
QString ModelManager::modelsDir()
{
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
+ "/models";
}
QString ModelManager::modelFilePath(const QString& name)
{
const QString n = name.isEmpty() ? defaultModelName() : name;
return modelsDir() + "/" + n;
}
bool ModelManager::isModelAvailable(const QString& name)
{
const QFileInfo fi(modelFilePath(name));
return fi.exists() && fi.size() > 0;
}