Skip to content

Commit

Permalink
Merge pull request #14 from Cyberhan123/some-feature
Browse files Browse the repository at this point in the history
fix and new feature
  • Loading branch information
Cyberhan123 authored Jan 21, 2024
2 parents 855165e + 11db74e commit c612bef
Show file tree
Hide file tree
Showing 26 changed files with 369 additions and 140 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
build: [
# { name: stable-diffusion-desktop, platform: linux/amd64, os: ubuntu-latest },
{ name: stable-diffusion-desktop, platform: linux/amd64, os: ubuntu-latest },
{ name: stable-diffusion-desktop, platform: windows/amd64, os: windows-latest },
{ name: stable-diffusion-desktop, platform: darwin/universal, os: macos-latest }
]
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
if: runner.os == 'Windows'
run: |
wails build --platform ${{ matrix.build.platform }} -webview2 download -nsis -o ${{ matrix.build.name }}
rm -rf ${{ matrix.build.name }}
Rename-Item -Path "${{ matrix.build.name }}" -NewName "${{ matrix.build.name }}.exe
shell: bash

- name: Build .app zip file
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/bin
node_modules
frontend/dist
/models/
*.exe
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ Download the latest release from [here](https://github.com/Cyberhan123/stable-di
- 16-bit, 32-bit float and 4-bit, 5-bit, 8-bit integer quantization support
- Accelerated memory-efficient CPU inference
- Auto-detect CPU and GPU and cross-platform support
- Full Nvidia ( CUDA12 ) GPU backend for GPU acceleration (Windows Only) and AMD GPU (Windows Only) come soon.
- Full Nvidia ( CUDA12 ) GPU backend and AMD GPU for GPU acceleration, Windows only.
- Note: AMD GPU support is experimental and may not work properly and must set correct `weight type` By your self, don't use `Auto` option!!.
- Can load ckpt, safetensors, gguf and diffusers models/checkpoints.
- Auto detect dark mode/ light mode
- Text Predict and Image Predict (up scaling come soon)
- TAESD support
- Sampling method
- `Euler A`
- `Euler`
Expand All @@ -41,15 +43,14 @@ Download the latest release from [here](https://github.com/Cyberhan123/stable-di
- [ ] Upscaling support
- [ ] Remote server support
- [ ] terminal show full progress bar
- [ ] TAESD support
- [ ] auto download model/checkpoint/lora
- [ ] auto update
- [ ] plugin support
- [ ] i18n support

## UI Preview
<p align="center">
<img src="./assets/sd_desktop_light.png" width="768x">
<img src="assets/sd_desktop_dark.png" width="768x">
</p>
<p align="center">
<img src="./assets/sd_desktop_dark.png" width="768x">
Expand Down
9 changes: 6 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ func NewApp() *App {
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.options = a.defaultUserSetting()
a.ctx = ctx

a.options = a.defaultUserSetting()
a.loadUserSetting()

model, err := sd.NewAutoModel(*a.options)
if err != nil {
runtime.LogError(ctx, err.Error())
}
a.ctx = ctx
a.sd = model
a.sd.SetLogCallback(func(level sd.LogLevel, text string) {
runtime.EventsEmit(ctx, "log", level, text)
Expand Down Expand Up @@ -299,6 +298,9 @@ func (a *App) loadUserSetting() bool {
}

a.options = &settings
if a.options.Threads <= 0 {
a.options.Threads = goruntime.NumCPU() - 2 // 2 threads for rest of the system
}
return true
}

Expand Down Expand Up @@ -339,6 +341,7 @@ func (a *App) defaultUserSetting() *sd.Options {
options.GpuEnable = false
options.FreeParamsImmediately = false
options.Threads = goruntime.NumCPU() - 2 // 2 threads for rest of the system
options.Wtype = sd.COUNT
return &options
}

Expand Down
Binary file modified assets/sd_desktop_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/sd_desktop_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion backend/stable-diffusion-cpp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/base64"
"errors"
"github.com/cyberhan123/stable-diffusion-desktop/backend/stable-diffusion-cpp/api"
"github.com/seasonjs/stable-diffusion"
sd "github.com/seasonjs/stable-diffusion"
"io"
"log"
"net"
Expand Down
31 changes: 9 additions & 22 deletions build/windows/installer/wails_tools.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
!include "FileFunc.nsh"

!ifndef INFO_PROJECTNAME
!define INFO_PROJECTNAME "{{.Name}}"
!define INFO_PROJECTNAME "stable-diffusion-desktop"
!endif
!ifndef INFO_COMPANYNAME
!define INFO_COMPANYNAME "{{.Info.CompanyName}}"
!define INFO_COMPANYNAME "Cyebrhan123"
!endif
!ifndef INFO_PRODUCTNAME
!define INFO_PRODUCTNAME "{{.Info.ProductName}}"
!define INFO_PRODUCTNAME "stable diffusion desktop"
!endif
!ifndef INFO_PRODUCTVERSION
!define INFO_PRODUCTVERSION "{{.Info.ProductVersion}}"
!define INFO_PRODUCTVERSION "1.0.0"
!endif
!ifndef INFO_COPYRIGHT
!define INFO_COPYRIGHT "{{.Info.Copyright}}"
!define INFO_COPYRIGHT "Copyright 2023 Cyberhan123"
!endif
!ifndef PRODUCT_EXECUTABLE
!define PRODUCT_EXECUTABLE "${INFO_PROJECTNAME}.exe"
Expand Down Expand Up @@ -203,20 +203,12 @@ RequestExecutionLevel "${REQUEST_EXECUTION_LEVEL}"

!macro wails.associateFiles
; Create file associations
{{range .Info.FileAssociations}}
!insertmacro APP_ASSOCIATE "{{.Ext}}" "{{.Name}}" "{{.Description}}" "$INSTDIR\{{.IconName}}.ico" "Open with ${INFO_PRODUCTNAME}" "$INSTDIR\${PRODUCT_EXECUTABLE} $\"%1$\""

File "..\{{.IconName}}.ico"
{{end}}

!macroend

!macro wails.unassociateFiles
; Delete app associations
{{range .Info.FileAssociations}}
!insertmacro APP_UNASSOCIATE "{{.Ext}}" "{{.Name}}"

Delete "$INSTDIR\{{.IconName}}.ico"
{{end}}

!macroend

!macro CUSTOM_PROTOCOL_ASSOCIATE PROTOCOL DESCRIPTION ICON COMMAND
Expand All @@ -235,15 +227,10 @@ RequestExecutionLevel "${REQUEST_EXECUTION_LEVEL}"

!macro wails.associateCustomProtocols
; Create custom protocols associations
{{range .Info.Protocols}}
!insertmacro CUSTOM_PROTOCOL_ASSOCIATE "{{.Scheme}}" "{{.Description}}" "$INSTDIR\${PRODUCT_EXECUTABLE},0" "$INSTDIR\${PRODUCT_EXECUTABLE} $\"%1$\""

{{end}}

!macroend

!macro wails.unassociateCustomProtocols
; Delete app custom protocol associations
{{range .Info.Protocols}}
!insertmacro CUSTOM_PROTOCOL_UNASSOCIATE "{{.Scheme}}"
{{end}}

!macroend
4 changes: 4 additions & 0 deletions embed_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package main

//go:embed backend/stable-diffusion-cpp/stable-diffusion-cpp-backend
var StableDiffusionCppBackend []byte
34 changes: 34 additions & 0 deletions embed_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
_ "embed"
"os"
"path/filepath"
)

//go:embed backend/stable-diffusion-cpp/stable-diffusion-cpp-backend.exe
var StableDiffusionCppBackend []byte

func releaseAdditionalFiles() error {
currentDir, err := os.Getwd()
if err != nil {
return err
}

relativePath := "stable-diffusion-cpp-backend.exe"
fullPath := filepath.Join(currentDir, relativePath)
if _, err := os.Stat(fullPath); err != nil {
//if os. {
//
//}
}

//data, err := embededData.ReadFile(fullPath)
//if err != nil {
// fmt.Println("无法读取嵌入的数据:", err)
// return
//}
//
//fmt.Println("嵌入的数据:", string(data))
return nil
}
2 changes: 1 addition & 1 deletion frontend/package.json.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7bf71b5bfcacc78a6f1e620adc62bfb9
6200e47500119837cd4a8de5ed4e6223
80 changes: 0 additions & 80 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,4 @@ body {
-webkit-font-smoothing: antialiased;
overflow-y: hidden;
overflow-x: hidden;
}

.row {
display: grid;
grid-template-columns: repeat(2, 1fr);
}

.col {
padding: 5px;
border: none;
}

.row-main {
display: grid;
grid-template-columns: 1fr 2fr;
}

.row-gen {
display: grid;
grid-template-columns: 1fr 1fr 2fr;
}
.image-gallery {
min-width: 300px;
min-height: 480px;
padding: 5px;
}

.image-gallery img {
border-radius: 5px;
}

.image-gallery .preview {
display: inline-block;
max-height: 100%;
margin: 1%;
}

.image-gallery .image-preview {
height: 85%;
}

.image-preview img {
height: 100%;
}

.image-info {
display: none;
}

.show-info {
width: calc(100% - 5px);
height: calc(100% - 5px);
position: absolute;
padding-left: 5px;
padding-top: 5px;
border-radius: 5px;
color: white;
background-image: linear-gradient(to bottom, black, transparent);
}

.image-gallery ul {
display: inline-block;
vertical-align: top;
width: 15%;
list-style: none;
padding: 1%;
max-height: 100%;
overflow-y: scroll;
}

.image-gallery li {
width: 100%;
}

.image-gallery li img {
width: 100%;
}

.image-gallery li .selected {
border: 2px solid #0363f2;
}
33 changes: 24 additions & 9 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import {useState} from 'react';
import {App as AntdApp, Button, ConfigProvider, Flex, Layout, Segmented, Space, theme} from "antd";
import {AlertOutlined, FileImageOutlined, FileOutlined, FontColorsOutlined, SettingOutlined} from "@ant-design/icons";
import {
AlertOutlined,
// DownloadOutlined,
FileImageOutlined,
FileOutlined,
FontColorsOutlined,
SettingOutlined
} from "@ant-design/icons";
import Predict from "./pages/Predict";
import {useRequest} from "ahooks";
import {GetOptions, LoadFromFile, SetOptions} from "../wailsjs/go/main/App";
import Settings from "./components/Settings";
import Settings from "./pages/Settings";

import './App.css'
import ModelHub from "./pages/ModelHub";

const {darkAlgorithm, defaultAlgorithm} = theme;

function App() {
const [model, setModel] = useState<string | number>("text")
const [tab, setTab] = useState<string | number>("text")
const [hasLoadModel, setHasLoadModel] = useState(false)
const [open, setOpen] = useState(false);
const [isDark, setIsDark] = useState<boolean>(window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches ?? false);
Expand All @@ -21,10 +29,8 @@ function App() {
manual: true
})
const {data: options, loading: optionsLoading} = useRequest(async () => {
const result = await GetOptions();
return result
return await GetOptions();
}, {
ready: !!open,
refreshDeps: [open]
})
const {runAsync: setOptions, loading: setOptionsLoading} = useRequest(async (params) => {
Expand All @@ -38,9 +44,9 @@ function App() {
<Layout.Content style={{height: "100vh", padding: 12}}>
<Flex justify={"space-between"}>
<Segmented
value={model}
value={tab}
onChange={async (value) => {
setModel(value)
setTab(value)
if (value === "text") {
await setOptions({
...options,
Expand All @@ -57,6 +63,7 @@ function App() {
options={[
{label: 'Text Predict Image', value: "text", icon: <FontColorsOutlined/>},
{label: 'Image Predict Image', value: "image", icon: <FileImageOutlined/>},
// {label: 'Model Hub', value: "model", icon: <DownloadOutlined/>},
]}
/>
<Space size={12}>
Expand Down Expand Up @@ -87,7 +94,15 @@ function App() {
</Button>
</Space>
</Flex>
<Predict hasLoadModel={hasLoadModel} predictType={model} isDark={isDark} loading={loadModelLoading || optionsLoading || setOptionsLoading}/>
{
(tab === "text" || tab === "image") &&
<Predict hasLoadModel={hasLoadModel} predictType={tab} isDark={isDark}
loading={loadModelLoading || optionsLoading || setOptionsLoading}/>
}
{
tab === "model" &&
<ModelHub/>
}
<Settings
open={open}
optionsLoading={setOptionsLoading || optionsLoading || loadModelLoading}
Expand Down
Loading

0 comments on commit c612bef

Please sign in to comment.