-
Notifications
You must be signed in to change notification settings - Fork 1
/
hub.go
90 lines (72 loc) · 1.49 KB
/
hub.go
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
package main
import (
"context"
"github.com/seasonjs/hf-hub/api"
"github.com/wailsapp/wails/v2/pkg/runtime"
"os"
"path/filepath"
"strings"
)
type Hub struct {
ctx context.Context
}
func NewHub() *App {
return &App{}
}
func (h *Hub) startup(ctx context.Context) {
h.ctx = ctx
}
type LocalModalTaskParams struct {
Migration string
ModelPath string
}
func (h *Hub) SetLocalModalTask(params LocalModalTaskParams) {
}
type HuggingfaceRepoTaskParams struct {
Repo string
}
func (h *Hub) SetHuggingfaceRepoTask(params HuggingfaceRepoTaskParams) *api.RepoInfo {
name := strings.Split(params.Repo, "/")
if len(name) != 2 {
return nil
}
if name[1] == "" {
return nil
}
builder, err := api.NewApiBuilder()
if err != nil {
runtime.LogError(h.ctx, err.Error())
return nil
}
hapi := builder.
WithCacheDir(h.GetHubPath()).
Build()
repo := api.NewRepo(params.Repo, api.Model)
info, err := hapi.Repo(repo).Info()
return info
}
func (h *Hub) GetHubPath() string {
//todo custom path
return h.defaultHubPath()
}
func (h *Hub) defaultHubPath() string {
homeDir, err := os.UserHomeDir()
if err != nil {
runtime.LogError(h.ctx, err.Error())
return ""
}
hubPath := filepath.Join(homeDir, "stable-diffusion-desktop", "hub")
return hubPath
}
func (h *Hub) SetHubPath(path string) bool {
//todo
return false
}
func (h *Hub) HubSettingsPath() string {
return h.GetHubPath() + "/settings.json"
}
func (h *Hub) GetHubSettings() string {
return ""
}
func (h *Hub) SetHubSettings() {
}