macOS
This commit is contained in:
parent
06a125b8d7
commit
b63370928d
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,3 +16,4 @@ __pycache__
|
||||
/backend-python/wkv_cuda
|
||||
*.exe
|
||||
*.old
|
||||
.DS_Store
|
||||
|
1
Makefile
1
Makefile
@ -10,6 +10,7 @@ build-windows:
|
||||
|
||||
build-macos:
|
||||
@echo ---- build for macos
|
||||
wails build -ldflags "-s -w"
|
||||
|
||||
dev:
|
||||
wails dev
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/minio/selfupdate"
|
||||
@ -13,7 +14,9 @@ import (
|
||||
|
||||
// App struct
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
ctx context.Context
|
||||
exDir string
|
||||
cmdPrefix string
|
||||
}
|
||||
|
||||
// NewApp creates a new App application struct
|
||||
@ -25,6 +28,14 @@ func NewApp() *App {
|
||||
// so we can call the runtime methods
|
||||
func (a *App) OnStartup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
ex, _ := os.Executable()
|
||||
a.exDir = filepath.Dir(ex)
|
||||
a.cmdPrefix = ""
|
||||
|
||||
if runtime.GOOS == "darwin" {
|
||||
a.exDir += "/../../../"
|
||||
a.cmdPrefix = "cd " + a.exDir + " && "
|
||||
}
|
||||
|
||||
a.downloadLoop()
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (a *App) DownloadFile(path string, url string) error {
|
||||
_, err := grab.Get(path, url)
|
||||
_, err := grab.Get(a.exDir+path, url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -81,7 +81,7 @@ func (a *App) AddToDownloadList(path string, url string) {
|
||||
downloadList = append(downloadList, DownloadStatus{
|
||||
resp: nil,
|
||||
Name: filepath.Base(path),
|
||||
Path: path,
|
||||
Path: a.exDir + path,
|
||||
Url: url,
|
||||
Downloading: true,
|
||||
})
|
||||
|
@ -2,7 +2,7 @@ package backend_golang
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -18,14 +18,14 @@ func (a *App) SaveJson(fileName string, jsonData any) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.WriteFile(fileName, text, 0644); err != nil {
|
||||
if err := os.WriteFile(a.exDir+fileName, text, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) ReadJson(fileName string) (any, error) {
|
||||
file, err := os.ReadFile(fileName)
|
||||
file, err := os.ReadFile(a.exDir + fileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -40,7 +40,7 @@ func (a *App) ReadJson(fileName string) (any, error) {
|
||||
}
|
||||
|
||||
func (a *App) FileExists(fileName string) bool {
|
||||
_, err := os.Stat(fileName)
|
||||
_, err := os.Stat(a.exDir + fileName)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ type FileInfo struct {
|
||||
}
|
||||
|
||||
func (a *App) ReadFileInfo(fileName string) (FileInfo, error) {
|
||||
info, err := os.Stat(fileName)
|
||||
info, err := os.Stat(a.exDir + fileName)
|
||||
if err != nil {
|
||||
return FileInfo{}, err
|
||||
}
|
||||
@ -65,7 +65,7 @@ func (a *App) ReadFileInfo(fileName string) (FileInfo, error) {
|
||||
}
|
||||
|
||||
func (a *App) ListDirFiles(dirPath string) ([]FileInfo, error) {
|
||||
files, err := os.ReadDir(dirPath)
|
||||
files, err := os.ReadDir(a.exDir + dirPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -87,7 +87,7 @@ func (a *App) ListDirFiles(dirPath string) ([]FileInfo, error) {
|
||||
}
|
||||
|
||||
func (a *App) DeleteFile(path string) error {
|
||||
err := os.Remove(path)
|
||||
err := os.Remove(a.exDir + path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -95,18 +95,18 @@ func (a *App) DeleteFile(path string) error {
|
||||
}
|
||||
|
||||
func (a *App) CopyFile(src string, dst string) error {
|
||||
sourceFile, err := os.Open(src)
|
||||
sourceFile, err := os.Open(a.exDir + src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer sourceFile.Close()
|
||||
|
||||
err = os.MkdirAll(dst[:strings.LastIndex(dst, "/")], 0755)
|
||||
err = os.MkdirAll(a.exDir+dst[:strings.LastIndex(dst, "/")], 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
destFile, err := os.Create(dst)
|
||||
destFile, err := os.Create(a.exDir + dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -120,7 +120,7 @@ func (a *App) CopyFile(src string, dst string) error {
|
||||
}
|
||||
|
||||
func (a *App) OpenFileFolder(path string) error {
|
||||
absPath, err := filepath.Abs(path)
|
||||
absPath, err := filepath.Abs(a.exDir + path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -131,10 +131,16 @@ func (a *App) OpenFileFolder(path string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case "darwin":
|
||||
fmt.Println("Running on macOS")
|
||||
cmd := exec.Command("open", "-R", absPath)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case "linux":
|
||||
fmt.Println("Running on Linux")
|
||||
println("unsupported OS")
|
||||
}
|
||||
return nil
|
||||
return errors.New("unsupported OS")
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func (a *App) ConvertModel(python string, modelPath string, strategy string, out
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return Cmd(python, "./backend-python/convert_model.py", "--in", modelPath, "--out", outPath, "--strategy", strategy)
|
||||
return Cmd(python, "./backend-python/convert_model.py", "--in", modelPath, "--out", outPath, "--strategy", `"`+strategy+`"`)
|
||||
}
|
||||
|
||||
func (a *App) DepCheck(python string) error {
|
||||
@ -37,7 +37,7 @@ func (a *App) DepCheck(python string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := exec.Command(python, "./backend-python/dep_check.py").CombinedOutput()
|
||||
out, err := exec.Command(python, a.exDir+"./backend-python/dep_check.py").CombinedOutput()
|
||||
if err != nil {
|
||||
return errors.New("DepCheck Error: " + string(out))
|
||||
}
|
||||
@ -63,7 +63,11 @@ func (a *App) InstallPyDep(python string, cnMirror bool) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, err = Cmd(python, "-m", "pip", "install", "torch==1.13.1", "torchvision==0.14.1", "torchaudio==0.13.1", "--index-url", "https://download.pytorch.org/whl/cu117")
|
||||
if runtime.GOOS == "windows" {
|
||||
_, err = Cmd(python, "-m", "pip", "install", "torch==1.13.1", "torchvision==0.14.1", "torchaudio==0.13.1", "--index-url", "https://download.pytorch.org/whl/cu117")
|
||||
} else {
|
||||
_, err = Cmd(python, "-m", "pip", "install", "torch", "torchvision", "torchaudio")
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -15,12 +15,8 @@ import (
|
||||
)
|
||||
|
||||
func Cmd(args ...string) (string, error) {
|
||||
path, err := filepath.Abs(args[0])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
args[0] = path
|
||||
if runtime.GOOS == "windows" {
|
||||
switch platform := runtime.GOOS; platform {
|
||||
case "windows":
|
||||
_, err := os.Stat("cmd-helper.bat")
|
||||
if err != nil {
|
||||
if err := os.WriteFile("./cmd-helper.bat", []byte("start %*"), 0644); err != nil {
|
||||
@ -31,13 +27,33 @@ func Cmd(args ...string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
path, err := filepath.Abs(args[0])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
args[0] = path
|
||||
|
||||
cmd := exec.Command(cmdHelper, args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(out), nil
|
||||
} else {
|
||||
case "darwin":
|
||||
ex, err := os.Executable()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
exDir := filepath.Dir(ex) + "/../../../"
|
||||
cmd := exec.Command("osascript", "-e", `tell application "Terminal" to do script "`+"cd "+exDir+" && "+strings.Join(args, " ")+`"`)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
cmd.Wait()
|
||||
return "", nil
|
||||
case "linux":
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
@ -46,9 +62,19 @@ func Cmd(args ...string) (string, error) {
|
||||
cmd.Wait()
|
||||
return "", nil
|
||||
}
|
||||
return "", errors.New("unsupported OS")
|
||||
}
|
||||
|
||||
func CopyEmbed(efs embed.FS) error {
|
||||
prefix := ""
|
||||
if runtime.GOOS == "darwin" {
|
||||
ex, err := os.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prefix = filepath.Dir(ex) + "/../../../"
|
||||
}
|
||||
|
||||
err := fs.WalkDir(efs, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
@ -61,6 +87,7 @@ func CopyEmbed(efs embed.FS) error {
|
||||
return err
|
||||
}
|
||||
|
||||
path = prefix + path
|
||||
err = os.MkdirAll(path[:strings.LastIndex(path, "/")], 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1,4 +1,3 @@
|
||||
import cyac
|
||||
import GPUtil
|
||||
import torch
|
||||
import rwkv
|
||||
|
@ -2,7 +2,6 @@ import pathlib
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Response, status as Status
|
||||
from pydantic import BaseModel
|
||||
from langchain.llms import RWKV
|
||||
from utils.rwkv import *
|
||||
from utils.torch import *
|
||||
import global_var
|
||||
|
@ -132,5 +132,6 @@
|
||||
"Are you sure you want to reset all configs? This will obtain the latest preset configs, but will override your custom configs and cannot be undone.": "你确定要重置所有配置吗?这会获取最新的预设配置,但会覆盖你的自定义配置,并且无法撤销",
|
||||
"Advanced": "高级",
|
||||
"Custom Python Path": "自定义Python路径",
|
||||
"Custom Models Path": "自定义模型路径"
|
||||
"Custom Models Path": "自定义模型路径",
|
||||
"MacOS is not supported yet, please convert manually.": "暂不支持MacOS, 请手动转换"
|
||||
}
|
@ -835,6 +835,11 @@ export const Configs: FC = observer(() => {
|
||||
</div>
|
||||
} />
|
||||
<ToolTipButton text={t('Convert')} desc={t('Convert model with these configs')} onClick={async () => {
|
||||
if(commonStore.platform=="darwin"){
|
||||
toast(t("MacOS is not supported yet, please convert manually."), { type: 'info' })
|
||||
return
|
||||
}
|
||||
|
||||
const modelPath = `${commonStore.settings.customModelsPath}/${selectedConfig.modelParameters.modelName}`;
|
||||
if (await FileExists(modelPath)) {
|
||||
const strategy = getStrategy(selectedConfig);
|
||||
|
@ -62,7 +62,7 @@ export const Downloads: FC = observer(() => {
|
||||
ContinueDownload(status.url);
|
||||
}} />}
|
||||
<ToolTipButton desc={t('Open Folder')} icon={<Folder20Regular />} onClick={() => {
|
||||
OpenFileFolder(status.path);
|
||||
OpenFileFolder(`${commonStore.settings.customModelsPath}/${status.name}`);
|
||||
}} />
|
||||
</div>
|
||||
</Field>
|
||||
|
0
frontend/wailsjs/go/backend_golang/App.d.ts
generated
vendored
Normal file → Executable file
0
frontend/wailsjs/go/backend_golang/App.d.ts
generated
vendored
Normal file → Executable file
0
frontend/wailsjs/go/backend_golang/App.js
generated
Normal file → Executable file
0
frontend/wailsjs/go/backend_golang/App.js
generated
Normal file → Executable file
0
frontend/wailsjs/go/models.ts
generated
Normal file → Executable file
0
frontend/wailsjs/go/models.ts
generated
Normal file → Executable file
Loading…
Reference in New Issue
Block a user