diff --git a/README.md b/README.md index ddd4bc98..8b3c8f0f 100644 --- a/README.md +++ b/README.md @@ -120,14 +120,19 @@ Sign up for an account at https://huggingface.co and find the models you want to - https://huggingface.co/runwayml/stable-diffusion-v1-5 -Download the conversion script from the `huggingface/diffusers` repository: - -- https://raw.githubusercontent.com/huggingface/diffusers/main/scripts/convert_stable_diffusion_checkpoint_to_onnx.py +Log into the HuggingFace CLI: ```shell -> wget https://raw.githubusercontent.com/huggingface/diffusers/main/scripts/convert_stable_diffusion_checkpoint_to_onnx.py +> huggingface-cli.exe login ``` +Issue an API token from https://huggingface.co/settings/tokens, naming it something memorable like `onnx-web`, and then +paste it into the prompt. + +Download the conversion script from the `huggingface/diffusers` repository to the root of this project: + +- https://raw.githubusercontent.com/huggingface/diffusers/main/scripts/convert_stable_diffusion_checkpoint_to_onnx.py + Run the conversion script with your desired model(s): ```shell @@ -136,8 +141,8 @@ Run the conversion script with your desired model(s): This will take a little while to convert each model. Stable diffusion v1.4 is about 6GB, v1.5 is at least 10GB or so. -You can verify that all of the steps up to this point worked correctly by attempting to run the basic `txt2img` script -provided with `diffusers` and included here as `api/setup-test.py`. +You can verify that all of the steps up to this point worked correctly by attempting to run the `api/setup-test.py` +script, which is a slight variation on the original txt2img script. ## Usage diff --git a/api/serve.py b/api/serve.py index 7060dbcc..518af797 100644 --- a/api/serve.py +++ b/api/serve.py @@ -117,4 +117,4 @@ def txt2img(): res = make_response(send_file(img_io, mimetype='image/png')) res.headers.add('Access-Control-Allow-Origin', '*') - return res \ No newline at end of file + return res diff --git a/docs/readme-preview.png b/docs/readme-preview.png index 1db835aa..e9c1682c 100644 Binary files a/docs/readme-preview.png and b/docs/readme-preview.png differ diff --git a/gui/Makefile b/gui/Makefile index 4989774d..75c20df4 100644 --- a/gui/Makefile +++ b/gui/Makefile @@ -30,6 +30,7 @@ build-shebang: build bundle: build node esbuild.js cp -v src/index.html out/ + cp -v examples/config.json out/ COVER_OPTS := --all \ --exclude ".eslintrc.js" \ @@ -54,16 +55,3 @@ lint: deps test: build MOCHA_FILE=out/test-results.xml yarn c8 $(COVER_OPTS) mocha $(MOCHA_OPTS) "out/**/Test*.js" - -# image-building targets -image: - podman build -t docker-push.artifacts.apextoaster.com/ssube/conan-discord:main -f Containerfile . - -image-local: ci - podman pull docker-push.artifacts.apextoaster.com/ssube/conan-discord:main - $(MAKE) image - podman push docker-push.artifacts.apextoaster.com/ssube/conan-discord:main - -# run targets -run: build - node out/src/index.js diff --git a/gui/examples/config.json b/gui/examples/config.json new file mode 100644 index 00000000..04ce3d9e --- /dev/null +++ b/gui/examples/config.json @@ -0,0 +1,5 @@ +{ + "api": { + "root": "http://ssube-desktop.home.holdmyran.ch:5000" + } +} \ No newline at end of file diff --git a/gui/serve.js b/gui/serve.js index 050406b5..10cabbb1 100644 --- a/gui/serve.js +++ b/gui/serve.js @@ -11,14 +11,33 @@ const root = process.cwd(); const portNum = parseInt(port, 10); +const contentTypes = [ + [/^.*\.html$/, 'text/html'], + [/^.*\.js$/, 'application/javascript'], + [/^.*\.json$/, 'text/json'], +]; + +function getContentType(path) { + for (const [regex, type] of contentTypes) { + if (regex.test(path)) { + return type; + } + } + + return 'unknown'; +} + const server = createServer((req, res) => { - readFile(join(root, 'out', req.url || 'index.html'), function (err, data) { + const path = join(root, 'out', req.url || 'index.html'); + readFile(path, function (err, data) { if (err) { res.writeHead(404); res.end(JSON.stringify(err)); return; } - res.writeHead(200); + res.writeHead(200, { + 'Content-Type': getContentType(path), + }); res.end(data); }); }); diff --git a/gui/src/config.ts b/gui/src/config.ts deleted file mode 100644 index d8e64de2..00000000 --- a/gui/src/config.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const CONFIG = { - api: { - root: 'http://ssube-desktop.home.holdmyran.ch:5000', - }, -}; diff --git a/gui/src/index.html b/gui/src/index.html index 59f3e26d..c44f2453 100644 --- a/gui/src/index.html +++ b/gui/src/index.html @@ -1,5 +1,4 @@
- + \ No newline at end of file diff --git a/gui/src/main.tsx b/gui/src/main.tsx index 1d848374..b03d70ea 100644 --- a/gui/src/main.tsx +++ b/gui/src/main.tsx @@ -1,15 +1,36 @@ import { mustExist } from '@apextoaster/js-utils'; import * as React from 'react'; import ReactDOM from 'react-dom/client'; -import { makeClient } from './api/client'; -import { OnnxWeb } from './components/OnnxWeb'; -import { CONFIG } from './config'; -export function main() { +import { makeClient } from './api/client.js'; +import { OnnxWeb } from './components/OnnxWeb.js'; + +export interface Config { + api: { + root: string; + } +} + +export async function loadConfig() { + const configPath = new URL('./config.json', window.origin); + const configReq = await fetch(configPath); + if (configReq.status === 200) { + return configReq.json(); + } else { + throw new Error('could not load config'); + } +} + +export async function main() { + const config = await loadConfig(); + const appElement = mustExist(document.getElementById('app')); const app = ReactDOM.createRoot(appElement); - const client = makeClient(CONFIG.api.root); + const client = makeClient(config.api.root); app.render(); } -main(); +window.addEventListener('load', () => { + console.log('launching onnx-web'); + main(); +}, false);