Spaces:
Runtime error
Runtime error
new backend
Browse files
frontend/src/lib/App.svelte
CHANGED
|
@@ -6,7 +6,7 @@
|
|
| 6 |
import PromptModal from '$lib/PromptModal.svelte';
|
| 7 |
import type { Room } from '@liveblocks/client';
|
| 8 |
import { COLORS, EMOJIS } from '$lib/constants';
|
| 9 |
-
import {
|
| 10 |
import { onMount } from 'svelte';
|
| 11 |
import {
|
| 12 |
isLoading,
|
|
@@ -44,11 +44,16 @@
|
|
| 44 |
const sessionHash = crypto.randomUUID();
|
| 45 |
|
| 46 |
const payload = {
|
| 47 |
-
fn_index:
|
| 48 |
-
data: [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
session_hash: sessionHash
|
| 50 |
};
|
| 51 |
-
const websocket = new WebSocket(
|
| 52 |
// websocket.onopen = async function (event) {
|
| 53 |
// websocket.send(JSON.stringify({ hash: sessionHash }));
|
| 54 |
// };
|
|
@@ -81,15 +86,18 @@
|
|
| 81 |
break;
|
| 82 |
case 'process_completed':
|
| 83 |
try {
|
| 84 |
-
const
|
| 85 |
-
const
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
$imagesList.push({
|
| 88 |
prompt: _prompt,
|
| 89 |
-
|
| 90 |
position: $clickedPosition
|
| 91 |
});
|
| 92 |
-
console.log(
|
| 93 |
$loadingState = data.success ? 'Complete' : 'Error';
|
| 94 |
} catch (e) {
|
| 95 |
$loadingState = e.message;
|
|
|
|
| 6 |
import PromptModal from '$lib/PromptModal.svelte';
|
| 7 |
import type { Room } from '@liveblocks/client';
|
| 8 |
import { COLORS, EMOJIS } from '$lib/constants';
|
| 9 |
+
import { PUBLIC_WS_INPAINTING } from '$env/static/public';
|
| 10 |
import { onMount } from 'svelte';
|
| 11 |
import {
|
| 12 |
isLoading,
|
|
|
|
| 44 |
const sessionHash = crypto.randomUUID();
|
| 45 |
|
| 46 |
const payload = {
|
| 47 |
+
fn_index: 0,
|
| 48 |
+
data: [
|
| 49 |
+
null,
|
| 50 |
+
//{ mask: null, image: null },
|
| 51 |
+
_prompt,
|
| 52 |
+
true
|
| 53 |
+
],
|
| 54 |
session_hash: sessionHash
|
| 55 |
};
|
| 56 |
+
const websocket = new WebSocket(PUBLIC_WS_INPAINTING);
|
| 57 |
// websocket.onopen = async function (event) {
|
| 58 |
// websocket.send(JSON.stringify({ hash: sessionHash }));
|
| 59 |
// };
|
|
|
|
| 86 |
break;
|
| 87 |
case 'process_completed':
|
| 88 |
try {
|
| 89 |
+
const imgBase64 = data.output.data[0] as string;
|
| 90 |
+
const isNSWF = data.output.data[1] as boolean;
|
| 91 |
+
|
| 92 |
+
const imgBlob = await base64ToBlob(imgBase64);
|
| 93 |
+
const imgURL = await uploadImage(imgBlob, _prompt);
|
| 94 |
+
|
| 95 |
$imagesList.push({
|
| 96 |
prompt: _prompt,
|
| 97 |
+
imgURL: imgURL,
|
| 98 |
position: $clickedPosition
|
| 99 |
});
|
| 100 |
+
console.log(imgURL);
|
| 101 |
$loadingState = data.success ? 'Complete' : 'Error';
|
| 102 |
} catch (e) {
|
| 103 |
$loadingState = e.message;
|
frontend/src/lib/Canvas.svelte
CHANGED
|
@@ -39,18 +39,19 @@
|
|
| 39 |
[-width * 0.1, -height * 0.1],
|
| 40 |
[width * 1.1, height * 1.1]
|
| 41 |
])
|
|
|
|
| 42 |
.on('zoom', zoomed);
|
| 43 |
|
| 44 |
select(canvasEl.parentElement)
|
| 45 |
.call(zoomHandler as any)
|
| 46 |
-
|
| 47 |
-
.on('pointermove', handlePointerMove)
|
| 48 |
-
.on('pointerleave', handlePointerLeave)
|
| 49 |
-
.on('dblclick.zoom', null)
|
| 50 |
-
.on('dblclick', () => {
|
| 51 |
$isPrompting = true;
|
| 52 |
$clickedPosition = $myPresence.cursor;
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
canvasCtx = canvasEl.getContext('2d') as CanvasRenderingContext2D;
|
| 56 |
canvasCtx.strokeStyle = 'blue';
|
|
@@ -59,14 +60,14 @@
|
|
| 59 |
});
|
| 60 |
|
| 61 |
function renderImages(imagesList) {
|
| 62 |
-
imagesList.forEach(({
|
| 63 |
// console.log(item);
|
| 64 |
const img = new Image();
|
| 65 |
img.onload = () => {
|
| 66 |
console.log(img);
|
| 67 |
canvasCtx.drawImage(img, position.x, position.y, img.width, img.height);
|
| 68 |
};
|
| 69 |
-
img.src =
|
| 70 |
});
|
| 71 |
}
|
| 72 |
|
|
|
|
| 39 |
[-width * 0.1, -height * 0.1],
|
| 40 |
[width * 1.1, height * 1.1]
|
| 41 |
])
|
| 42 |
+
.tapDistance(10)
|
| 43 |
.on('zoom', zoomed);
|
| 44 |
|
| 45 |
select(canvasEl.parentElement)
|
| 46 |
.call(zoomHandler as any)
|
| 47 |
+
.on('dblclick.zoom', () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
$isPrompting = true;
|
| 49 |
$clickedPosition = $myPresence.cursor;
|
| 50 |
+
return null;
|
| 51 |
+
})
|
| 52 |
+
// .call(zoomHandler.scaleTo as any, 1 / scale)
|
| 53 |
+
.on('pointermove', handlePointerMove)
|
| 54 |
+
.on('pointerleave', handlePointerLeave);
|
| 55 |
|
| 56 |
canvasCtx = canvasEl.getContext('2d') as CanvasRenderingContext2D;
|
| 57 |
canvasCtx.strokeStyle = 'blue';
|
|
|
|
| 60 |
});
|
| 61 |
|
| 62 |
function renderImages(imagesList) {
|
| 63 |
+
imagesList.forEach(({ imgURL, position }) => {
|
| 64 |
// console.log(item);
|
| 65 |
const img = new Image();
|
| 66 |
img.onload = () => {
|
| 67 |
console.log(img);
|
| 68 |
canvasCtx.drawImage(img, position.x, position.y, img.width, img.height);
|
| 69 |
};
|
| 70 |
+
img.src = imgURL;
|
| 71 |
});
|
| 72 |
}
|
| 73 |
|