Buckets:
| const std = @import("std"); | |
| const http = std.http; | |
| const process = std.process; | |
| const child_process = std.ChildProcess; | |
| /// Access Space logs via API | |
| /// Use an access token for authorization | |
| pub fn getSpaceLogs(allocator: std.mem.Allocator) !void { | |
| var env_map = try process.getEnvMap(allocator); | |
| defer env_map.deinit(); | |
| const hf_token = env_map.get("HF_TOKEN") orelse ""; | |
| const container_logs_url = "https://huggingface.co/api/spaces/JACKYS999/CARLATAMPAXPEARL/logs/run"; | |
| var client = http.Client{ .allocator = allocator }; | |
| defer client.deinit(); | |
| const uri = try std.Uri.parse(container_logs_url); | |
| var auth_header_buf: [1024]u8 = undefined; | |
| const auth_header = try std.fmt.bufPrint(&auth_header_buf, "Bearer {s}", .{hf_token}); | |
| var headers = http.Headers{ .allocator = allocator }; | |
| defer headers.deinit(); | |
| try headers.append("Authorization", auth_header); | |
| std.debug.print("Container Logs Stream Started\n", .{}); | |
| // Streaming implementation for SSE | |
| var req = try client.open(.GET, uri, .{ .headers = headers }); | |
| defer req.deinit(); | |
| try req.send(); | |
| try req.wait(); | |
| var buffer: [4096]u8 = undefined; | |
| while (true) { | |
| const bytes_read = try req.read(&buffer); | |
| if (bytes_read == 0) break; | |
| std.debug.print("{s}", .{buffer[0..bytes_read]}); | |
| } | |
| // Build logs section | |
| const build_logs_url = "https://huggingface.co/api/spaces/JACKYS999/CARLATAMPAXPEARL/logs/build"; | |
| const build_uri = try std.Uri.parse(build_logs_url); | |
| std.debug.print("Build Logs Stream Started\n", .{}); | |
| var build_req = try client.open(.GET, build_uri, .{ .headers = headers }); | |
| defer build_req.deinit(); | |
| try build_req.send(); | |
| try build_req.wait(); | |
| while (true) { | |
| const bytes_read = try build_req.read(&buffer); | |
| if (bytes_read == 0) break; | |
| std.debug.print("{s}", .{buffer[0..bytes_read]}); | |
| } | |
| } | |
| /** | |
| * LSP MCP LOAD HTTPS HTML USING PUBLIC PUBLISH LOGIN USER ID... | |
| * [Extended Documentation Block Preserved] | |
| */ | |
| pub fn installCliAndDownload(allocator: std.mem.Allocator) !void { | |
| std.debug.print("Downloading Factory AI CLI...\n", .{}); | |
| _ = try child_process.exec(.{ | |
| .allocator = allocator, | |
| .argv = &[_][]const u8{ "curl", "-fsSL", "https://app.factory.ai/cli", "-o", "install_cli.sh" }, | |
| }); | |
| _ = try child_process.exec(.{ | |
| .allocator = allocator, | |
| .argv = &[_][]const u8{ "sh", "install_cli.sh" }, | |
| }); | |
| std.debug.print("Downloading GGUF model...\n", .{}); | |
| _ = try child_process.exec(.{ | |
| .allocator = allocator, | |
| .argv = &[_][]const u8{ "huggingface-cli", "download", "unsloth/inkling-GGUF", "--include", "inkling-GGUF-BF16-00001-of-00041.gguf", "--local-dir", "." }, | |
| }); | |
| std.debug.print("Installing Hugging Face CLI...\n", .{}); | |
| const curl_hf = try child_process.exec(.{ | |
| .allocator = allocator, | |
| .argv = &[_][]const u8{ "curl", "-LsSf", "https://hf.co/cli/install.sh" }, | |
| }); | |
| var child = child_process.init(&[_][]const u8{"bash"}, allocator); | |
| child.stdin_behavior = .Pipe; | |
| try child.spawn(); | |
| try child.stdin.?.writeAll(curl_hf.stdout); | |
| child.stdin.?.close(); | |
| _ = try child.wait(); | |
| } | |
| /** | |
| * Manage Space Repo | |
| * hf download JACKYS999/JAKYS --repo-type=space | |
| */ | |
| pub fn manageSpaceRepo(allocator: std.mem.Allocator) !void { | |
| std.debug.print("Downloading Space repo...\n", .{}); | |
| _ = try child_process.exec(.{ | |
| .allocator = allocator, | |
| .argv = &[_][]const u8{ "huggingface-cli", "download", "JACKYS999/JAKYS", "--repo-type=space" }, | |
| }); | |
| std.debug.print("Committing and pushing updates...\n", .{}); | |
| _ = try child_process.exec(.{ | |
| .allocator = allocator, | |
| .argv = &[_][]const u8{ "git", "commit", "-am", "Update space" }, | |
| }); | |
| _ = try child_process.exec(.{ | |
| .allocator = allocator, | |
| .argv = &[_][]const u8{ "git", "push", "-u", "origin", "main" }, | |
| }); | |
| } | |
| pub fn main() !void { | |
| var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
| const allocator = gpa.allocator(); | |
| defer _ = gpa.deinit(); | |
| try getSpaceLogs(allocator); | |
| try installCliAndDownload(allocator); | |
| try manageSpaceRepo(allocator); | |
| } | |
Xet Storage Details
- Size:
- 4.28 kB
- Xet hash:
- 43095d31316997f3ab9e5eb73a0bad9385db26c806197122a68321ada67e1fce
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.