Spaces:
Runtime error
Runtime error
fix upload screenshot
Browse files
frontend/src/lib/Buttons/ShareWithCommunity.svelte
CHANGED
|
@@ -16,18 +16,32 @@
|
|
| 16 |
$canvasEl.toBlob(resolve as BlobCallback, 'image/jpeg', 0.95);
|
| 17 |
});
|
| 18 |
isUploading = true;
|
|
|
|
| 19 |
await createCommunityPost(blob);
|
|
|
|
| 20 |
isUploading = false;
|
| 21 |
}
|
| 22 |
|
| 23 |
async function createCommunityPost(canvasBlob: Blob) {
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
const canvasImage = `<img src="${canvasURL.url}" style="width:100%" width="1000" height="1000">`;
|
| 32 |
const descriptionMd = `#### Stable Diffusion Multiplayer:
|
| 33 |
### [${$selectedRoomID}](https://huggingface.co/spaces/huggingface-projects/stable-diffusion-multiplayer?roomid=${$selectedRoomID})
|
|
|
|
| 16 |
$canvasEl.toBlob(resolve as BlobCallback, 'image/jpeg', 0.95);
|
| 17 |
});
|
| 18 |
isUploading = true;
|
| 19 |
+
|
| 20 |
await createCommunityPost(blob);
|
| 21 |
+
|
| 22 |
isUploading = false;
|
| 23 |
}
|
| 24 |
|
| 25 |
async function createCommunityPost(canvasBlob: Blob) {
|
| 26 |
+
let canvasURL: {
|
| 27 |
+
url: string;
|
| 28 |
+
filename: string;
|
| 29 |
+
} | null = null;
|
| 30 |
+
try {
|
| 31 |
+
canvasURL = await uploadImage(canvasBlob, {
|
| 32 |
+
prompt: 'canvas',
|
| 33 |
+
position: { x: 0, y: 0 },
|
| 34 |
+
date: new Date().getTime(),
|
| 35 |
+
id: nanoid(),
|
| 36 |
+
room: $selectedRoomID || 'default'
|
| 37 |
+
});
|
| 38 |
+
} catch (err) {
|
| 39 |
+
console.error(err);
|
| 40 |
+
}
|
| 41 |
+
if (!canvasURL) {
|
| 42 |
+
console.error('Failed to upload image');
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
const canvasImage = `<img src="${canvasURL.url}" style="width:100%" width="1000" height="1000">`;
|
| 46 |
const descriptionMd = `#### Stable Diffusion Multiplayer:
|
| 47 |
### [${$selectedRoomID}](https://huggingface.co/spaces/huggingface-projects/stable-diffusion-multiplayer?roomid=${$selectedRoomID})
|
frontend/src/lib/utils.ts
CHANGED
|
@@ -45,9 +45,11 @@ export async function uploadImage(imagBlob: Blob, params: {
|
|
| 45 |
method: 'POST',
|
| 46 |
body: formData
|
| 47 |
});
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
export function round(pos: number, canvasSize: {
|
| 53 |
width: number;
|
|
|
|
| 45 |
method: 'POST',
|
| 46 |
body: formData
|
| 47 |
});
|
| 48 |
+
if (response.status === 200) {
|
| 49 |
+
const data = await response.json();
|
| 50 |
+
return data;
|
| 51 |
+
}
|
| 52 |
+
throw new Error('Failed to upload image');
|
| 53 |
}
|
| 54 |
export function round(pos: number, canvasSize: {
|
| 55 |
width: number;
|
stablediffusion-infinity/app.py
CHANGED
|
@@ -354,7 +354,7 @@ async def upload_file(image: Image.Image, prompt: str, room_id: str, image_key:
|
|
| 354 |
async def create_upload_file(file: UploadFile):
|
| 355 |
contents = await file.read()
|
| 356 |
file_size = len(contents)
|
| 357 |
-
if not 0 < file_size <
|
| 358 |
raise HTTPException(
|
| 359 |
status_code=status.HTTP_400_BAD_REQUEST,
|
| 360 |
detail='Supported file size is less than 2 MB'
|
|
|
|
| 354 |
async def create_upload_file(file: UploadFile):
|
| 355 |
contents = await file.read()
|
| 356 |
file_size = len(contents)
|
| 357 |
+
if not 0 < file_size < 100E+06:
|
| 358 |
raise HTTPException(
|
| 359 |
status_code=status.HTTP_400_BAD_REQUEST,
|
| 360 |
detail='Supported file size is less than 2 MB'
|