From 6b4545b3bfbbaac9f91b27e18e03e5b8a4c81481 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Thu, 5 Jan 2023 00:44:52 -0600 Subject: [PATCH] make image params a type, image controls a component --- README.md | 9 +++ gui/src/api/client.ts | 14 +++-- gui/src/components/ImageControl.tsx | 86 +++++++++++++++++++++++++++++ gui/src/components/Txt2Img.tsx | 18 +++--- 4 files changed, 113 insertions(+), 14 deletions(-) create mode 100644 gui/src/components/ImageControl.tsx diff --git a/README.md b/README.md index 0b163599..8a01c684 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ # ONNX Web This is a web GUI for ONNX models, providing a way to run AMD GPU-accelerated models on Windows with a remote web UI. + +## Install + +Based on: + +- https://gist.github.com/harishanand95/75f4515e6187a6aa3261af6ac6f61269 +- https://gist.github.com/averad/256c507baa3dcc9464203dc14610d674A +- https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-AMD-GPUs +- https://www.travelneil.com/stable-diffusion-updates.html diff --git a/gui/src/api/client.ts b/gui/src/api/client.ts index f72feefd..857aa4d1 100644 --- a/gui/src/api/client.ts +++ b/gui/src/api/client.ts @@ -4,6 +4,8 @@ export interface Txt2ImgParams { prompt: string; cfg: number; steps: number; + width: number; + height: number; } export interface ApiClient { @@ -25,16 +27,16 @@ export function makeClient(root: string, f = fetch): ApiClient { return { async txt2img(params: Txt2ImgParams): Promise { if (doesExist(pending)) { - console.log('skipping duplicate request, one is already pending'); + console.log('skipping request, one is already pending'); return pending; } - const { prompt, cfg, steps } = params; - const url = new URL('/txt2img', root); - url.searchParams.append('cfg', cfg.toFixed(0)); - url.searchParams.append('prompt', prompt); - url.searchParams.append('steps', steps.toFixed(0)); + url.searchParams.append('cfg', params.cfg.toFixed(0)); + url.searchParams.append('steps', params.steps.toFixed(0)); + url.searchParams.append('width', params.width.toFixed(0)); + url.searchParams.append('height', params.height.toFixed(0)); + url.searchParams.append('prompt', params.prompt); pending = f(url).then((res) => { pending = undefined; diff --git a/gui/src/components/ImageControl.tsx b/gui/src/components/ImageControl.tsx new file mode 100644 index 00000000..a38b5c8f --- /dev/null +++ b/gui/src/components/ImageControl.tsx @@ -0,0 +1,86 @@ +import { doesExist } from '@apextoaster/js-utils'; +import { Container, Stack, TextField } from '@mui/material'; +import * as React from 'react'; + +export interface ImageParams { + cfg: number; + steps: number; + width: number; + height: number; +} + +export interface ImageControlProps { + params: ImageParams; + onChange?: (params: ImageParams) => void; +} + +export function ImageControl(props: ImageControlProps) { + const { params } = props; + + return + + { + if (doesExist(props.onChange)) { + props.onChange({ + ...params, + cfg: parseInt(event.target.value, 10), + }); + } + }} + /> + { + if (doesExist(props.onChange)) { + props.onChange({ + ...params, + steps: parseInt(event.target.value, 10), + }); + } + }} + /> + + + { + if (doesExist(props.onChange)) { + props.onChange({ + ...params, + width: parseInt(event.target.value, 10), + }); + } + }} + /> + { + if (doesExist(props.onChange)) { + props.onChange({ + ...params, + height: parseInt(event.target.value, 10), + }); + } + }} + /> + + ; +} \ No newline at end of file diff --git a/gui/src/components/Txt2Img.tsx b/gui/src/components/Txt2Img.tsx index 444571bf..1179f413 100644 --- a/gui/src/components/Txt2Img.tsx +++ b/gui/src/components/Txt2Img.tsx @@ -2,6 +2,7 @@ import { Box, Button, Stack, TextField } from '@mui/material'; import * as React from 'react'; import { ApiClient } from '../api/client.js'; +import { ImageControl, ImageParams } from './ImageControl.js'; const { useState } = React; @@ -13,12 +14,16 @@ export function Txt2Img(props: Txt2ImgProps) { const { client } = props; const [image, setImage] = useState(''); - const [cfg, setCfg] = useState(5); const [prompt, setPrompt] = useState('an astronaut eating a hamburger'); - const [steps, setSteps] = useState(20); + const [params, setParams] = useState({ + cfg: 6, + steps: 25, + width: 512, + height: 512, + }) async function getImage() { - const image = await client.txt2img({ prompt, cfg, steps }); + const image = await client.txt2img({ ...params, prompt }); console.log(prompt, image); setImage(image); } @@ -36,11 +41,8 @@ export function Txt2Img(props: Txt2ImgProps) { txt2img mode - { - setCfg(parseInt(event.target.value, 10)); - }} /> - { - setSteps(parseInt(event.target.value, 10)); + { + setParams(params); }} /> { setPrompt(event.target.value);