Spaces:
Runtime error
Runtime error
share works, route + for hf.space
Browse files- frontend/src/lib/App.svelte +1 -1
- frontend/src/lib/Buttons/ShareWithCommunity.svelte +29 -6
- frontend/src/lib/Icons/LoadingIcon.svelte +0 -1
- frontend/src/lib/utils.ts +5 -2
- frontend/src/routes/{+layout.svelte β +/+layout.svelte} +1 -1
- frontend/src/routes/{+page.svelte β +/+page.svelte} +0 -0
- frontend/src/routes/{+page.ts β +/+page.ts} +0 -0
- stablediffusion-infinity/app.py +1 -1
- stablediffusion-infinity/rooms.db +0 -0
frontend/src/lib/App.svelte
CHANGED
|
@@ -124,7 +124,7 @@
|
|
| 124 |
const imgURL = await uploadImage(imgBlob, prompt, key);
|
| 125 |
const promptImg = {
|
| 126 |
prompt,
|
| 127 |
-
imgURL: imgURL,
|
| 128 |
position,
|
| 129 |
date: new Date().getTime(),
|
| 130 |
id: nanoid()
|
|
|
|
| 124 |
const imgURL = await uploadImage(imgBlob, prompt, key);
|
| 125 |
const promptImg = {
|
| 126 |
prompt,
|
| 127 |
+
imgURL: imgURL.filename,
|
| 128 |
position,
|
| 129 |
date: new Date().getTime(),
|
| 130 |
id: nanoid()
|
frontend/src/lib/Buttons/ShareWithCommunity.svelte
CHANGED
|
@@ -1,16 +1,39 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import { createEventDispatcher } from 'svelte';
|
| 3 |
import IconCommunity from '$lib/Icons/IconCommunity.svelte';
|
| 4 |
import LoadingIcon from '$lib/Icons/LoadingIcon.svelte';
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
function handleClick() {
|
| 10 |
if (isUploading) {
|
| 11 |
return;
|
| 12 |
}
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
| 15 |
</script>
|
| 16 |
|
|
@@ -21,7 +44,7 @@
|
|
| 21 |
title="Share with community"
|
| 22 |
>
|
| 23 |
{#if isUploading}
|
| 24 |
-
<LoadingIcon classList="animate-spin max-w-[
|
| 25 |
{:else}
|
| 26 |
<IconCommunity />
|
| 27 |
{/if}
|
|
|
|
| 1 |
<script lang="ts">
|
|
|
|
| 2 |
import IconCommunity from '$lib/Icons/IconCommunity.svelte';
|
| 3 |
import LoadingIcon from '$lib/Icons/LoadingIcon.svelte';
|
| 4 |
+
import { uploadImage } from '$lib/utils';
|
| 5 |
+
import { canvasEl } from '$lib/store';
|
| 6 |
|
| 7 |
+
let isUploading: boolean = false;
|
| 8 |
|
| 9 |
+
async function handleClick() {
|
|
|
|
| 10 |
if (isUploading) {
|
| 11 |
return;
|
| 12 |
}
|
| 13 |
+
const blob: Blob = await new Promise((resolve) => {
|
| 14 |
+
$canvasEl.toBlob(resolve as BlobCallback, 'image/jpeg', 0.95);
|
| 15 |
+
});
|
| 16 |
+
isUploading = true;
|
| 17 |
+
await createCommunityPost(blob);
|
| 18 |
+
isUploading = false;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
async function createCommunityPost(canvasBlob: Blob) {
|
| 22 |
+
const canvasURL = await uploadImage(canvasBlob, 'canvas', 'canvas');
|
| 23 |
+
const canvasImage = `<img src="${canvasURL.url}" style="width:100%" width="1000" height="1000">`;
|
| 24 |
+
const descriptionMd = `#### Stable Diffusion Multiplayer:
|
| 25 |
+
<div style="display: flex; overflow: scroll; column-gap: 0.75rem;">
|
| 26 |
+
${canvasImage}
|
| 27 |
+
</div>`;
|
| 28 |
+
|
| 29 |
+
const params = new URLSearchParams({
|
| 30 |
+
description: descriptionMd
|
| 31 |
+
});
|
| 32 |
+
const paramsStr = params.toString();
|
| 33 |
+
window.open(
|
| 34 |
+
`https://huggingface.co/spaces/huggingface-projects/diffuse-the-rest/discussions/new?${paramsStr}`,
|
| 35 |
+
'_blank'
|
| 36 |
+
);
|
| 37 |
}
|
| 38 |
</script>
|
| 39 |
|
|
|
|
| 44 |
title="Share with community"
|
| 45 |
>
|
| 46 |
{#if isUploading}
|
| 47 |
+
<LoadingIcon classList="animate-spin max-w-[25px]" />
|
| 48 |
{:else}
|
| 49 |
<IconCommunity />
|
| 50 |
{/if}
|
frontend/src/lib/Icons/LoadingIcon.svelte
CHANGED
|
@@ -5,7 +5,6 @@
|
|
| 5 |
<svg
|
| 6 |
class={classList}
|
| 7 |
width="51"
|
| 8 |
-
height="51"
|
| 9 |
viewBox="0 0 21 21"
|
| 10 |
fill="none"
|
| 11 |
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
| 5 |
<svg
|
| 6 |
class={classList}
|
| 7 |
width="51"
|
|
|
|
| 8 |
viewBox="0 0 21 21"
|
| 9 |
fill="none"
|
| 10 |
xmlns="http://www.w3.org/2000/svg"
|
frontend/src/lib/utils.ts
CHANGED
|
@@ -20,7 +20,10 @@ export function base64ToBlob(base64image: string): Promise<Blob> {
|
|
| 20 |
img.src = base64image;
|
| 21 |
});
|
| 22 |
}
|
| 23 |
-
export async function uploadImage(imagBlob: Blob, prompt: string, key: string): Promise<
|
|
|
|
|
|
|
|
|
|
| 24 |
// simple regex slugify string for file name
|
| 25 |
const promptSlug = slugify(prompt);
|
| 26 |
|
|
@@ -38,7 +41,7 @@ export async function uploadImage(imagBlob: Blob, prompt: string, key: string):
|
|
| 38 |
});
|
| 39 |
const res = await response.json();
|
| 40 |
|
| 41 |
-
return res
|
| 42 |
}
|
| 43 |
const MAX = 512 * 5 - 512
|
| 44 |
|
|
|
|
| 20 |
img.src = base64image;
|
| 21 |
});
|
| 22 |
}
|
| 23 |
+
export async function uploadImage(imagBlob: Blob, prompt: string, key: string): Promise<{
|
| 24 |
+
url: string;
|
| 25 |
+
filename: string;
|
| 26 |
+
}> {
|
| 27 |
// simple regex slugify string for file name
|
| 28 |
const promptSlug = slugify(prompt);
|
| 29 |
|
|
|
|
| 41 |
});
|
| 42 |
const res = await response.json();
|
| 43 |
|
| 44 |
+
return res;
|
| 45 |
}
|
| 46 |
const MAX = 512 * 5 - 512
|
| 47 |
|
frontend/src/routes/{+layout.svelte β +/+layout.svelte}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
<script>
|
| 2 |
-
import '
|
| 3 |
</script>
|
| 4 |
|
| 5 |
<slot />
|
|
|
|
| 1 |
<script>
|
| 2 |
+
import '../../app.css';
|
| 3 |
</script>
|
| 4 |
|
| 5 |
<slot />
|
frontend/src/routes/{+page.svelte β +/+page.svelte}
RENAMED
|
File without changes
|
frontend/src/routes/{+page.ts β +/+page.ts}
RENAMED
|
File without changes
|
stablediffusion-infinity/app.py
CHANGED
|
@@ -313,7 +313,7 @@ async def autorize(request: Request, db: sqlite3.Connection = Depends(get_db)):
|
|
| 313 |
raise Exception(response.status_code, response.text)
|
| 314 |
|
| 315 |
|
| 316 |
-
@ app.post('/api/uploadfile
|
| 317 |
async def create_upload_file(background_tasks: BackgroundTasks, file: UploadFile):
|
| 318 |
contents = await file.read()
|
| 319 |
file_size = len(contents)
|
|
|
|
| 313 |
raise Exception(response.status_code, response.text)
|
| 314 |
|
| 315 |
|
| 316 |
+
@ app.post('/api/uploadfile')
|
| 317 |
async def create_upload_file(background_tasks: BackgroundTasks, file: UploadFile):
|
| 318 |
contents = await file.read()
|
| 319 |
file_size = len(contents)
|
stablediffusion-infinity/rooms.db
CHANGED
|
Binary files a/stablediffusion-infinity/rooms.db and b/stablediffusion-infinity/rooms.db differ
|
|
|