-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhf_fetch_models.cpp
More file actions
107 lines (93 loc) · 3.8 KB
/
hf_fetch_models.cpp
File metadata and controls
107 lines (93 loc) · 3.8 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Simple HuggingFace model downloader using curl
// Downloads model files from HuggingFace repositories to local cache
#include "eddy/core/app_dir.hpp"
#include "eddy/core/model_configs.hpp"
#include "eddy/utils/ensure_models.hpp"
#include <iostream>
#include <filesystem>
#include <string>
namespace fs = std::filesystem;
using namespace eddy::model_configs;
void print_usage(const char* prog) {
std::cout << "Usage: " << prog << " [OPTIONS]\n\n";
std::cout << "Options:\n";
std::cout << " --model <name> Model name (default: parakeet-v2)\n";
std::cout << " --target <dir> Target directory (default: cache directory)\n";
std::cout << " --help Show this help\n\n";
std::cout << "Examples:\n";
std::cout << " " << prog << " --model parakeet-v2\n";
std::cout << " " << prog << " --target C:\\path\\to\\models\n";
}
int main(int argc, char** argv) {
// Start with default model configuration
std::string model_name = "parakeet-v2";
std::string target_dir;
// Parse arguments
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "--help" || arg == "-h") {
print_usage(argv[0]);
return 0;
}
else if (arg == "--model" && i + 1 < argc) {
model_name = argv[++i];
}
else if (arg == "--target" && i + 1 < argc) {
target_dir = argv[++i];
}
else {
std::cerr << "ERROR: Unknown argument: " << arg << "\n\n";
print_usage(argv[0]);
return 1;
}
}
// Look up model configuration
auto it = MODEL_MAP.find(model_name);
if (it == MODEL_MAP.end()) {
std::cerr << "ERROR: Unknown model: " << model_name << "\n";
std::cerr << "Available models: parakeet-v2\n";
return 1;
}
const eddy::ModelConfig& config = it->second;
// Set target directory if not specified
if (target_dir.empty()) {
try {
target_dir = (eddy::get_models_dir() / config.cache_subdir / "files").string();
} catch (const std::exception& e) {
std::cerr << "ERROR: Could not determine cache directory: " << e.what() << "\n";
return 1;
}
}
std::cout << "================================================================================\n";
std::cout << "HuggingFace Model Downloader\n";
std::cout << "================================================================================\n";
std::cout << "Model: " << config.cache_subdir << "\n";
std::cout << "Repository: " << config.repo_id << "\n";
std::cout << "Target: " << target_dir << "\n";
std::cout << "Files: " << config.required_files.size() << " files\n";
std::cout << "================================================================================\n\n";
// Progress callback
auto progress_callback = [](const std::string& filename, int current, int total) {
std::cout << "[" << current << "/" << total << "] " << filename << "\n";
};
// Download models using library function
std::string error_msg;
bool success = eddy::parakeet::download_models(
config,
fs::path(target_dir),
&error_msg,
progress_callback,
true // skip_existing
);
std::cout << "\n================================================================================\n";
if (success) {
std::cout << "Download completed successfully!\n";
std::cout << "================================================================================\n";
return 0;
} else {
std::cout << "Download failed!\n";
std::cout << "================================================================================\n";
std::cerr << "\nError: " << error_msg << "\n";
return 1;
}
}