Skip to content

Commit

Permalink
🐛 fix: Fix ImageInfo reload (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Nov 29, 2023
1 parent 4be9f36 commit 8b17a70
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
16 changes: 8 additions & 8 deletions javascript/main.js

Large diffs are not rendered by default.

46 changes: 32 additions & 14 deletions src/modules/ImageInfo/features/formatInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,49 @@ const formatPrompt = (prompt: string) => {
export const formatInfo = (info: string) => {
if (!info || info === 'undefined') return;
if (!info.includes('<br>')) return;
const data = info.split('<br>').filter(Boolean);
const config = data[2] || data[1];
const data = info?.split('<br>').filter(Boolean);

let position: any;
let negative: any;
let config: any;

switch (data.length) {
case 1: {
config = data[0] || info;
break;
}
case 2: {
if (data[0].includes('Negative prompt:')) {
negative = data[0];
config = data[1];
} else {
position = data[0];
config = data[1];
}
break;
}
case 3: {
position = data[0];
negative = data[1];
config = data[2];
}
}

if (!config.includes(',')) return;
const clearConfigs = config
.split(',')
.map((item) => item.trim())
.map((item: any) => item?.trim())
.filter(Boolean);

const configs: any = {};

for (const item of clearConfigs) {
const items = item.split(':');
configs[items[0].trim()] = items[1].trim();
}

let position = data[0];
let negative = data[2] ? data[1] : '';

if (position.includes('Negative prompt:')) {
negative = position;
position = '';
configs[items[0]?.trim()] = items[1]?.trim();
}

position = formatPrompt(position);
negative = formatPrompt(negative.split('Negative prompt: ')[1]);
position = position ? formatPrompt(position) : '';
negative = negative ? formatPrompt(negative.split('Negative prompt: ')[1]) : '';

return {
config: configs,
Expand Down
5 changes: 1 addition & 4 deletions src/modules/ImageInfo/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const ImageInfo = (parentId: string, containerId: string) => {
const settingsDiv = document.createElement('div') as HTMLDivElement;
settingsDiv.id = containerId.replace('#', '');

(gradioApp().querySelector(parentId) as HTMLDivElement).insertBefore(
settingsDiv,
(gradioApp().querySelector(parentId) as HTMLDivElement).firstChild,
);
(gradioApp().querySelector(parentId) as HTMLDivElement).append(settingsDiv);

createRoot(settingsDiv).render(
<StrictMode>
Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import react from '@vitejs/plugin-react-swc';
import { consola } from 'consola';
import dotenv from 'dotenv';
import { resolve } from 'node:path';
import * as process from 'node:process';
Expand All @@ -11,7 +12,7 @@ const isProduction = process.env.NODE_ENV === 'production';
const SD_HOST = process.env.SD_HOST || '127.0.0.1';
const SD_PORT = process.env.SD_PORT || 7860;

console.log(SD_HOST, SD_PORT);
consola.info('Proxy:', `http://${SD_HOST}:${SD_PORT}`);
export default defineConfig({
base: '/dev',
build: {
Expand Down

0 comments on commit 8b17a70

Please sign in to comment.