Spaces:
Runtime error
Runtime error
liveblocks auth api
Browse files
frontend/.env.development.example
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
PUBLIC_WS_INPAINTING="ws://0.0.0.0:7860/gradio/queue/join"
|
2 |
PUBLIC_UPLOADS="https://d26smi9133w0oo.cloudfront.net/uploads"
|
3 |
-
|
|
|
1 |
PUBLIC_WS_INPAINTING="ws://0.0.0.0:7860/gradio/queue/join"
|
2 |
PUBLIC_UPLOADS="https://d26smi9133w0oo.cloudfront.net/uploads"
|
3 |
+
PUBLIC_API_BASE="/server/api"
|
frontend/.env.example
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
PUBLIC_WS_INPAINTING="wss://spaces.huggingface.tech/huggingface-projects/stable-diffusion-multiplayer/gradio/queue/join"
|
2 |
PUBLIC_UPLOADS="https://d26smi9133w0oo.cloudfront.net/uploads"
|
3 |
-
|
|
|
1 |
PUBLIC_WS_INPAINTING="wss://spaces.huggingface.tech/huggingface-projects/stable-diffusion-multiplayer/gradio/queue/join"
|
2 |
PUBLIC_UPLOADS="https://d26smi9133w0oo.cloudfront.net/uploads"
|
3 |
+
PUBLIC_API_BASE="/embed/huggingface-projects/stable-diffusion-multiplayer/api"
|
frontend/src/lib/constants.ts
CHANGED
@@ -5,24 +5,5 @@ export const COLORS = Object.values(colors)
|
|
5 |
.map((e) => e['200'])
|
6 |
.slice(0, 18);
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
'๐ถ',
|
11 |
-
'๐ฑ',
|
12 |
-
'๐ญ',
|
13 |
-
'๐น',
|
14 |
-
'๐ฐ',
|
15 |
-
'๐ฆ',
|
16 |
-
'๐ป',
|
17 |
-
'๐ผ',
|
18 |
-
'๐จ',
|
19 |
-
'๐ฏ',
|
20 |
-
'๐ฆ',
|
21 |
-
'๐ฎ',
|
22 |
-
'๐ฒ',
|
23 |
-
'๐',
|
24 |
-
'๐',
|
25 |
-
'๐',
|
26 |
-
'๐',
|
27 |
-
'๐'
|
28 |
-
];
|
|
|
5 |
.map((e) => e['200'])
|
6 |
.slice(0, 18);
|
7 |
|
8 |
+
export const EMOJIS = ['๐', '๐', '๐', '๐', '๐ฆ', '๐', '๐', '๐', '๐ฆ', '๐ฆ', '๐ท', '๐ฆ', '๐ข', '๐', '๐ฆ', '๐ฆ', '๐ฆ', '๐', '๐ฆ', '๐ ', '๐', '๐ก', '๐ฌ', '๐ฆ', '๐ณ', '๐', '๐', '๐
', '๐', '๐ฆ', '๐ฆ', '๐ฆง', '๐', '๐ฆ', '๐ฆ', '๐ช', '๐ซ', '๐ฆ', '๐', '๐', '๐', '๐', '๐',
|
9 |
+
'๐', '๐', '๐', '๐', '๐ฉ', '๐', '๐', '๐ฆ', '๐ฆ
', '๐ฆ', '๐ฆข', '๐ฆ', '๐ฆ', '๐ฆ', '๐ฆ', '๐', '๐', '๐ฟ', '๐', '๐ฟ', '๐ฆ', '๐ฆ', '๐ป', '๐ป', '๐จ', '๐ผ', '๐ต', '๐', '๐', '๐', '๐', '๐', '๐ฒ', '๐ฆ', '๐ฆ', '๐', '๐ข', '๐ฆ', '๐', '๐ฆ', '๐ง', '๐ฆ
', '๐ฆ', '๐ฆ', '๐ฆ']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frontend/src/lib/utils.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import {
|
2 |
|
3 |
export function base64ToBlob(base64image: string): Promise<Blob> {
|
4 |
return new Promise((resolve) => {
|
@@ -32,7 +32,7 @@ export async function uploadImage(imagBlob: Blob, prompt: string, key: string):
|
|
32 |
const formData = new FormData()
|
33 |
formData.append('file', file)
|
34 |
|
35 |
-
const response = await fetch(
|
36 |
method: 'POST',
|
37 |
body: formData
|
38 |
});
|
|
|
1 |
+
import { PUBLIC_API_BASE } from '$env/static/public';
|
2 |
|
3 |
export function base64ToBlob(base64image: string): Promise<Blob> {
|
4 |
return new Promise((resolve) => {
|
|
|
32 |
const formData = new FormData()
|
33 |
formData.append('file', file)
|
34 |
|
35 |
+
const response = await fetch(PUBLIC_API_BASE + "/uploadfile", {
|
36 |
method: 'POST',
|
37 |
body: formData
|
38 |
});
|
frontend/src/routes/+layout.ts
CHANGED
@@ -1 +1,6 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { PUBLIC_API_BASE } from '$env/static/public';
|
2 |
+
|
3 |
+
export async function load({ fetch }) {
|
4 |
+
const rooms = await fetch(PUBLIC_API_BASE + "/rooms").then((res) => res.json());
|
5 |
+
return { rooms };
|
6 |
+
}
|
frontend/src/routes/+page.svelte
CHANGED
@@ -15,11 +15,18 @@
|
|
15 |
import LiveblocksProvider from '$lib/liveblocks/LiveblocksProvider.svelte';
|
16 |
import RoomProvider from '$lib/liveblocks/RoomProvider.svelte';
|
17 |
import App from '$lib/App.svelte';
|
|
|
|
|
|
|
|
|
18 |
|
19 |
let roomId: string;
|
20 |
let loaded = false;
|
21 |
let client: Client;
|
22 |
|
|
|
|
|
|
|
23 |
onMount(() => {
|
24 |
document.addEventListener('wheel', (e) => e.preventDefault(), { passive: false });
|
25 |
|
@@ -29,7 +36,8 @@
|
|
29 |
|
30 |
// Connect to the authentication API for Liveblocks
|
31 |
client = createClient({
|
32 |
-
publicApiKey: 'pk_test_JlUZGH3kQmhmZQiqU2l8eIi5'
|
|
|
33 |
});
|
34 |
|
35 |
loaded = true;
|
|
|
15 |
import LiveblocksProvider from '$lib/liveblocks/LiveblocksProvider.svelte';
|
16 |
import RoomProvider from '$lib/liveblocks/RoomProvider.svelte';
|
17 |
import App from '$lib/App.svelte';
|
18 |
+
import type { PageData } from './$types';
|
19 |
+
import { PUBLIC_API_BASE } from '$env/static/public';
|
20 |
+
|
21 |
+
export let data: PageData;
|
22 |
|
23 |
let roomId: string;
|
24 |
let loaded = false;
|
25 |
let client: Client;
|
26 |
|
27 |
+
$: {
|
28 |
+
console.log('data changed', data);
|
29 |
+
}
|
30 |
onMount(() => {
|
31 |
document.addEventListener('wheel', (e) => e.preventDefault(), { passive: false });
|
32 |
|
|
|
36 |
|
37 |
// Connect to the authentication API for Liveblocks
|
38 |
client = createClient({
|
39 |
+
// publicApiKey: 'pk_test_JlUZGH3kQmhmZQiqU2l8eIi5'
|
40 |
+
authEndpoint: PUBLIC_API_BASE + '/auth'
|
41 |
});
|
42 |
|
43 |
loaded = true;
|
stablediffusion-infinity/app.py
CHANGED
@@ -3,7 +3,7 @@ import os
|
|
3 |
|
4 |
from pathlib import Path
|
5 |
import uvicorn
|
6 |
-
from fastapi import FastAPI, BackgroundTasks, HTTPException, UploadFile, Depends, status
|
7 |
from fastapi.staticfiles import StaticFiles
|
8 |
from fastapi.middleware.cors import CORSMiddleware
|
9 |
from fastapi_utils.tasks import repeat_every
|
@@ -21,6 +21,7 @@ import boto3
|
|
21 |
import magic
|
22 |
import sqlite3
|
23 |
import requests
|
|
|
24 |
|
25 |
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
|
26 |
AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY')
|
@@ -36,6 +37,7 @@ FILE_TYPES = {
|
|
36 |
'image/jpeg': 'jpg',
|
37 |
}
|
38 |
DB_PATH = Path("rooms.db")
|
|
|
39 |
app = FastAPI()
|
40 |
|
41 |
print("DB_PATH", DB_PATH)
|
@@ -55,7 +57,6 @@ def get_db():
|
|
55 |
db.close()
|
56 |
|
57 |
|
58 |
-
|
59 |
s3 = boto3.client(service_name='s3',
|
60 |
aws_access_key_id=AWS_ACCESS_KEY_ID,
|
61 |
aws_secret_access_key=AWS_SECRET_KEY)
|
@@ -115,6 +116,7 @@ def get_model():
|
|
115 |
# model["img2img"]
|
116 |
|
117 |
|
|
|
118 |
# get_model()
|
119 |
|
120 |
|
@@ -280,13 +282,32 @@ async def sync_rooms():
|
|
280 |
print(e)
|
281 |
print("Rooms update failed")
|
282 |
|
283 |
-
|
|
|
284 |
async def get_rooms(db: sqlite3.Connection = Depends(get_db)):
|
285 |
rooms = db.execute("SELECT * FROM rooms").fetchall()
|
286 |
return rooms
|
287 |
|
288 |
|
289 |
-
@app.post('/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
async def create_upload_file(background_tasks: BackgroundTasks, file: UploadFile):
|
291 |
contents = await file.read()
|
292 |
file_size = len(contents)
|
|
|
3 |
|
4 |
from pathlib import Path
|
5 |
import uvicorn
|
6 |
+
from fastapi import FastAPI, BackgroundTasks, HTTPException, UploadFile, Depends, status, Request
|
7 |
from fastapi.staticfiles import StaticFiles
|
8 |
from fastapi.middleware.cors import CORSMiddleware
|
9 |
from fastapi_utils.tasks import repeat_every
|
|
|
21 |
import magic
|
22 |
import sqlite3
|
23 |
import requests
|
24 |
+
import uuid
|
25 |
|
26 |
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
|
27 |
AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY')
|
|
|
37 |
'image/jpeg': 'jpg',
|
38 |
}
|
39 |
DB_PATH = Path("rooms.db")
|
40 |
+
|
41 |
app = FastAPI()
|
42 |
|
43 |
print("DB_PATH", DB_PATH)
|
|
|
57 |
db.close()
|
58 |
|
59 |
|
|
|
60 |
s3 = boto3.client(service_name='s3',
|
61 |
aws_access_key_id=AWS_ACCESS_KEY_ID,
|
62 |
aws_secret_access_key=AWS_SECRET_KEY)
|
|
|
116 |
# model["img2img"]
|
117 |
|
118 |
|
119 |
+
# init model on startup
|
120 |
# get_model()
|
121 |
|
122 |
|
|
|
282 |
print(e)
|
283 |
print("Rooms update failed")
|
284 |
|
285 |
+
|
286 |
+
@app.get('/api/rooms')
|
287 |
async def get_rooms(db: sqlite3.Connection = Depends(get_db)):
|
288 |
rooms = db.execute("SELECT * FROM rooms").fetchall()
|
289 |
return rooms
|
290 |
|
291 |
|
292 |
+
@app.post('/api/auth')
|
293 |
+
async def autorize(request: Request):
|
294 |
+
data = await request.json()
|
295 |
+
room = data["room"]
|
296 |
+
payload = {
|
297 |
+
"userId": str(uuid.uuid4()),
|
298 |
+
"userInfo": {
|
299 |
+
"name": "Anon"
|
300 |
+
}}
|
301 |
+
|
302 |
+
response = requests.post(f"https://api.liveblocks.io/v2/rooms/{room}/authorize",
|
303 |
+
headers={"Authorization": f"Bearer {LIVEBLOCKS_SECRET}"}, json=payload)
|
304 |
+
if response.status_code == 200:
|
305 |
+
return response.json()
|
306 |
+
else:
|
307 |
+
raise Exception(response.status_code, response.text)
|
308 |
+
|
309 |
+
|
310 |
+
@ app.post('/api/uploadfile/')
|
311 |
async def create_upload_file(background_tasks: BackgroundTasks, file: UploadFile):
|
312 |
contents = await file.read()
|
313 |
file_size = len(contents)
|