radames HF staff commited on
Commit
67cbe97
1 Parent(s): 4408af3

liveblocks icon

Browse files
frontend/src/lib/Buttons/PPButton.svelte CHANGED
@@ -11,7 +11,7 @@
11
  {#if isLoading}
12
  <span>paiting... </span>{:else}
13
  <span
14
- class="rounded-sm h-6 w-6 flex justify-center items-center border-2 border-dashed border-violet-700 mr-2"
15
  >
16
  +
17
  </span>
@@ -24,6 +24,6 @@
24
  @apply disabled:opacity-50 dark:bg-white dark:text-black bg-black text-white rounded-2xl text-xs shadow-sm focus:outline-none focus:border-gray-400;
25
  } */
26
  .button-paint {
27
- @apply text-sm font-mono bg-violet-100 text-violet-900 min-w-[25ch] flex justify-center items-center disabled:opacity-50 rounded-xl px-3 py-1 shadow-sm focus:outline-none focus:border-gray-400;
28
  }
29
  </style>
11
  {#if isLoading}
12
  <span>paiting... </span>{:else}
13
  <span
14
+ class="rounded-sm h-4 w-4 flex justify-center items-center border-2 border-dashed border-violet-700 mr-2"
15
  >
16
  +
17
  </span>
24
  @apply disabled:opacity-50 dark:bg-white dark:text-black bg-black text-white rounded-2xl text-xs shadow-sm focus:outline-none focus:border-gray-400;
25
  } */
26
  .button-paint {
27
+ @apply text-xs md:text-sm font-mono bg-violet-100 text-violet-900 min-w-[25ch] flex justify-center items-center disabled:opacity-50 rounded-xl px-3 py-1 shadow-sm focus:outline-none focus:border-gray-400;
28
  }
29
  </style>
frontend/src/lib/Buttons/RoomsSelector.svelte CHANGED
@@ -12,7 +12,7 @@
12
  .map((_, i) => ({ label: `room ${i}`, total: ~~Math.random() * 20, capacity: 20 }));
13
 
14
  let selectedRoomID = 0;
15
- let collapsed = true;
16
  $: selectedRoom = rooms[selectedRoomID];
17
 
18
  function clickHandler(event: Event) {
@@ -30,15 +30,17 @@
30
 
31
  <!-- svelte-ignore a11y-click-events-have-key-events -->
32
  <div
33
- class="bg-violet-100 text-violet-900 px-3 py-1 font-mono font-medium tracking-tight relative z-0
34
  {isLoading ? 'opacity-50' : ''}
35
  {collapsed ? 'rounded-xl' : 'rounded-b-xl'}"
36
  bind:this={boxEl}
37
  >
38
  {#if !collapsed}
39
- <div class="absolute z-20 left-0 right-0 bottom-full rounded-t-xl bg-violet-100 px-1 py-1 overflow-y-scroll max-h-80">
 
 
40
  <ul class="relative">
41
- <li class="grid-row gap-2 pb-3 sticky top-0 bg-violet-100">
42
  <Room />
43
  <span> room </span>
44
  <People />
@@ -49,7 +51,10 @@
49
  <!-- svelte-ignore a11y-invalid-attribute -->
50
  <a
51
  href="#"
52
- on:click|preventDefault={() => (selectedRoomID = i)}
 
 
 
53
  class="grid-row gap-2 hover:bg-gray-300
54
  {i === selectedRoomID ? 'text-green-600' : ''}"
55
  >
12
  .map((_, i) => ({ label: `room ${i}`, total: ~~Math.random() * 20, capacity: 20 }));
13
 
14
  let selectedRoomID = 0;
15
+ let collapsed = false;
16
  $: selectedRoom = rooms[selectedRoomID];
17
 
18
  function clickHandler(event: Event) {
30
 
31
  <!-- svelte-ignore a11y-click-events-have-key-events -->
32
  <div
33
+ class="text-xs md:text-sm bg-violet-100 text-violet-900 px-3 py-1 font-mono font-medium tracking-tight relative z-0 min-w-[25ch]
34
  {isLoading ? 'opacity-50' : ''}
35
  {collapsed ? 'rounded-xl' : 'rounded-b-xl'}"
36
  bind:this={boxEl}
37
  >
38
  {#if !collapsed}
39
+ <div
40
+ class="absolute z-20 left-0 right-0 bottom-full rounded-t-xl bg-violet-100 px-1 overflow-y-scroll max-h-80"
41
+ >
42
  <ul class="relative">
43
+ <li class="grid-row gap-2 pb-3 sticky top-0 bg-violet-100 py-2">
44
  <Room />
45
  <span> room </span>
46
  <People />
51
  <!-- svelte-ignore a11y-invalid-attribute -->
52
  <a
53
  href="#"
54
+ on:click|preventDefault={() => {
55
+ selectedRoomID = i;
56
+ collapsed = true;
57
+ }}
58
  class="grid-row gap-2 hover:bg-gray-300
59
  {i === selectedRoomID ? 'text-green-600' : ''}"
60
  >
frontend/src/lib/Icons/LiveBlocks.svelte ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let classList = '';
3
+ </script>
4
+
5
+ <svg
6
+ class={classList}
7
+ width="123"
8
+ height="44"
9
+ viewBox="0 0 123 44"
10
+ fill="none"
11
+ xmlns="http://www.w3.org/2000/svg"
12
+ >
13
+ <rect
14
+ opacity="0.5"
15
+ x="0.25"
16
+ y="0.25"
17
+ width="122.5"
18
+ height="43.5"
19
+ rx="6.75"
20
+ fill="#1F2937"
21
+ stroke="#3A4C64"
22
+ stroke-width="0.5"
23
+ />
24
+ <path
25
+ d="M44.9102 16.8569H45.8514V14.778H47.1691C48.364 14.778 49.1497 14.0577 49.1497 12.9528C49.1497 11.8397 48.364 11.1277 47.1691 11.1277H44.9102V16.8569ZM47.0954 11.9461C47.7666 11.9461 48.1921 12.3308 48.1921 12.9528C48.1921 13.5667 47.7584 13.9595 47.0872 13.9595H45.8514V11.9461H47.0954Z"
26
+ fill="#A3BAD9"
27
+ />
28
+ <path
29
+ d="M51.5649 16.9059C52.8417 16.9059 53.701 16.0465 53.701 14.7615C53.701 13.4847 52.8417 12.6172 51.5649 12.6172C50.2881 12.6172 49.4287 13.4847 49.4287 14.7615C49.4287 16.0465 50.2881 16.9059 51.5649 16.9059ZM51.5649 16.1529C50.8201 16.1529 50.3372 15.5718 50.3372 14.7615C50.3372 13.9513 50.8201 13.3702 51.5649 13.3702C52.3097 13.3702 52.8007 13.9513 52.8007 14.7615C52.8007 15.5718 52.3097 16.1529 51.5649 16.1529Z"
30
+ fill="#A3BAD9"
31
+ />
32
+ <path
33
+ d="M55.233 16.857H56.1906L57.1073 14.0088L57.9912 16.857H58.9406L60.332 12.6665H59.4317L58.4414 15.8748L57.5247 12.6665H56.7144L55.7568 15.8748L54.7992 12.6665H53.8662L55.233 16.857Z"
34
+ fill="#A3BAD9"
35
+ />
36
+ <path
37
+ d="M62.6424 16.9059C63.6818 16.9059 64.3857 16.2757 64.533 15.449H63.6491C63.5263 15.9156 63.1335 16.1856 62.5933 16.1856C61.8976 16.1856 61.4475 15.7191 61.4229 15.0071V14.9498H64.5821C64.5985 14.8352 64.6067 14.7206 64.6067 14.6142C64.5821 13.3865 63.7719 12.6172 62.5605 12.6172C61.3247 12.6172 60.498 13.4766 60.498 14.7697C60.498 16.0547 61.3247 16.9059 62.6424 16.9059ZM61.4556 14.3032C61.5211 13.7057 62.004 13.3292 62.5687 13.3292C63.1826 13.3292 63.6164 13.6812 63.69 14.3032H61.4556Z"
38
+ fill="#A3BAD9"
39
+ />
40
+ <path
41
+ d="M67.4411 12.6665C66.7536 12.6665 66.418 12.9448 66.2052 13.2967L66.107 12.6665H65.3213V16.857H66.2052V14.7536C66.2052 14.107 66.4589 13.4931 67.2447 13.4931H67.6375V12.6665H67.4411Z"
42
+ fill="#A3BAD9"
43
+ />
44
+ <path
45
+ d="M69.9725 16.9059C71.0119 16.9059 71.7158 16.2757 71.8631 15.449H70.9792C70.8564 15.9156 70.4635 16.1856 69.9234 16.1856C69.2277 16.1856 68.7775 15.7191 68.753 15.0071V14.9498H71.9122C71.9286 14.8352 71.9368 14.7206 71.9368 14.6142C71.9122 13.3865 71.1019 12.6172 69.8906 12.6172C68.6548 12.6172 67.8281 13.4766 67.8281 14.7697C67.8281 16.0547 68.6548 16.9059 69.9725 16.9059ZM68.7857 14.3032C68.8512 13.7057 69.3341 13.3292 69.8988 13.3292C70.5127 13.3292 70.9464 13.6812 71.0201 14.3032H68.7857Z"
46
+ fill="#A3BAD9"
47
+ />
48
+ <path
49
+ d="M75.8352 13.2475C75.5651 12.8792 75.1149 12.6173 74.4765 12.6173C73.3391 12.6173 72.4961 13.4685 72.4961 14.7616C72.4961 16.1039 73.3391 16.906 74.4765 16.906C75.1395 16.906 75.5733 16.5949 75.8433 16.2266L75.9497 16.8569H76.7191V11.1277H75.8352V13.2475ZM74.6238 16.1612C73.8875 16.1612 73.4046 15.5883 73.4046 14.7616C73.4046 13.9432 73.8875 13.3702 74.6238 13.3702C75.3605 13.3702 75.8433 13.9432 75.8433 14.778C75.8433 15.5883 75.3605 16.1612 74.6238 16.1612Z"
50
+ fill="#A3BAD9"
51
+ />
52
+ <path
53
+ d="M81.9193 12.6173C81.2727 12.6173 80.839 12.9119 80.5607 13.2884V11.1277H79.6768V16.8569H80.4461L80.5525 16.2512C80.8144 16.6277 81.2646 16.906 81.9193 16.906C83.0652 16.906 83.9 16.0466 83.9 14.7616C83.9 13.4112 83.0652 12.6173 81.9193 12.6173ZM81.772 16.1612C81.0354 16.1612 80.5525 15.5801 80.5525 14.7534C80.5525 13.9432 81.0354 13.3702 81.772 13.3702C82.5086 13.3702 82.9997 13.9432 82.9997 14.7616C82.9997 15.5883 82.5086 16.1612 81.772 16.1612Z"
54
+ fill="#A3BAD9"
55
+ />
56
+ <path
57
+ d="M85.6277 16.8815L85.4641 17.2908C85.3331 17.6345 85.2513 17.7164 84.9075 17.7164H84.2855V18.4939H85.2349C85.8487 18.4939 86.0288 18.1911 86.2907 17.5117L88.1895 12.6665H87.2483L86.1106 15.8503L84.9402 12.6665H83.999L85.6277 16.8815Z"
58
+ fill="#A3BAD9"
59
+ />
60
+ <path d="M45.1162 32.4821H47.2144V22.0654H45.1162V32.4821Z" fill="#A3BAD9" />
61
+ <path
62
+ d="M49.7329 24.0148C50.4175 24.0148 50.9532 23.5088 50.9532 22.8392C50.9532 22.1546 50.4175 21.6487 49.7329 21.6487C49.0484 21.6487 48.5127 22.1546 48.5127 22.8392C48.5127 23.5088 49.0484 24.0148 49.7329 24.0148ZM48.6764 32.482H50.7895V24.8332H48.6764V32.482Z"
63
+ fill="#A3BAD9"
64
+ />
65
+ <path
66
+ d="M54.2461 32.4823H56.8503L59.6033 24.8335H57.4009L55.5854 30.3394L53.7402 24.8335H51.4932L54.2461 32.4823Z"
67
+ fill="#A3BAD9"
68
+ />
69
+ <path
70
+ d="M63.718 32.5713C65.7567 32.5713 67.0811 31.3808 67.3192 29.8927H65.2507C65.0722 30.607 64.4769 30.979 63.6287 30.979C62.5722 30.979 61.8728 30.3243 61.8281 29.2379V29.1338H67.3787C67.4234 28.8957 67.4382 28.6427 67.4382 28.4195C67.4085 26.1725 65.8609 24.7439 63.5692 24.7439C61.2031 24.7439 59.6406 26.2915 59.6406 28.6725C59.6406 31.0385 61.1734 32.5713 63.718 32.5713ZM61.8728 27.7647C61.9918 26.857 62.6763 26.3064 63.5841 26.3064C64.5365 26.3064 65.1763 26.8272 65.3251 27.7647H61.8728Z"
71
+ fill="#A3BAD9"
72
+ />
73
+ <path
74
+ d="M72.9898 24.744C71.9332 24.744 71.1891 25.1904 70.6832 25.8005V22.0654H68.585V32.4821H70.4153L70.6237 31.4404C71.1148 32.0952 71.8737 32.5714 72.9749 32.5714C75.0434 32.5714 76.5315 31.0089 76.5315 28.6428C76.5315 26.2172 75.0434 24.744 72.9898 24.744ZM72.5136 30.8601C71.3678 30.8601 70.6534 29.9523 70.6534 28.6428C70.6534 27.3482 71.3678 26.4553 72.5136 26.4553C73.6594 26.4553 74.4035 27.3482 74.4035 28.6577C74.4035 29.9672 73.6594 30.8601 72.5136 30.8601Z"
75
+ fill="#A3BAD9"
76
+ />
77
+ <path d="M77.6973 32.4821H79.7955V22.0654H77.6973V32.4821Z" fill="#A3BAD9" />
78
+ <path
79
+ d="M84.9927 32.5713C87.4332 32.5713 89.0254 31.0237 89.0254 28.6576C89.0254 26.3064 87.4332 24.7439 84.9927 24.7439C82.5522 24.7439 80.96 26.3064 80.96 28.6576C80.96 31.0088 82.5522 32.5713 84.9927 32.5713ZM84.9927 30.86C83.8171 30.86 83.1028 29.9522 83.1028 28.6576C83.1028 27.3629 83.8171 26.4552 84.9927 26.4552C86.1683 26.4552 86.8975 27.3629 86.8975 28.6576C86.8975 29.9522 86.1683 30.86 84.9927 30.86Z"
80
+ fill="#A3BAD9"
81
+ />
82
+ <path
83
+ d="M93.7816 32.5713C95.865 32.5713 97.2489 31.4254 97.5465 29.5951H95.3441C95.1953 30.3689 94.6447 30.86 93.8263 30.86C92.7251 30.86 92.0257 29.9671 92.0257 28.6576C92.0257 27.3629 92.7251 26.4552 93.8263 26.4552C94.6447 26.4552 95.1655 26.9314 95.3441 27.6903H97.5316C97.234 25.8748 95.9394 24.7439 93.856 24.7439C91.4304 24.7439 89.8828 26.2915 89.8828 28.6576C89.8828 31.0683 91.356 32.5713 93.7816 32.5713Z"
84
+ fill="#A3BAD9"
85
+ />
86
+ <path
87
+ d="M98.6514 32.4821H100.75V30.622L101.895 29.3869L103.83 32.4821H106.256L103.354 27.8392L106.107 24.8333H103.741L100.75 28.0773V22.0654H98.6514V32.4821Z"
88
+ fill="#A3BAD9"
89
+ />
90
+ <path
91
+ d="M106.188 29.9375C106.277 31.5744 107.72 32.5714 109.848 32.5714C111.902 32.5714 113.33 31.6042 113.33 30.0863C113.33 28.3601 111.872 27.9583 110.116 27.7798C109.015 27.6458 108.36 27.5863 108.36 27.006C108.36 26.5149 108.896 26.2173 109.714 26.2173C110.562 26.2173 111.143 26.5893 111.202 27.1994H113.211C113.107 25.6369 111.693 24.7292 109.64 24.7292C107.676 24.7143 106.351 25.7113 106.351 27.2292C106.351 28.8065 107.735 29.2083 109.521 29.4167C110.756 29.5804 111.277 29.625 111.277 30.25C111.277 30.7857 110.741 31.0685 109.863 31.0685C108.836 31.0685 108.256 30.6071 108.182 29.9375H106.188Z"
92
+ fill="#A3BAD9"
93
+ />
94
+ <path
95
+ d="M32.4824 8.67236H11.649C10.0053 8.67236 8.67285 10.0048 8.67285 11.6486V32.4819C8.67285 34.1256 10.0053 35.4581 11.649 35.4581H32.4824C34.1261 35.4581 35.4586 34.1256 35.4586 32.4819V11.6486C35.4586 10.0048 34.1261 8.67236 32.4824 8.67236Z"
96
+ fill="url(#paint0_radial_253_107)"
97
+ />
98
+ <path
99
+ fill-rule="evenodd"
100
+ clip-rule="evenodd"
101
+ d="M24.8953 17.78H15.0332L17.8712 20.7599V24.875L24.8953 17.78ZM19.2193 26.294H29.0814L26.2434 23.3141V19.199L19.2193 26.294Z"
102
+ fill="white"
103
+ />
104
+ <defs>
105
+ <radialGradient
106
+ id="paint0_radial_253_107"
107
+ cx="0"
108
+ cy="0"
109
+ r="1"
110
+ gradientUnits="userSpaceOnUse"
111
+ gradientTransform="translate(4.7524 1.97593) rotate(45.3703) scale(40.7748 35.4976)"
112
+ >
113
+ <stop stop-color="#FF0099" />
114
+ <stop offset="1" stop-color="#FF7A00" />
115
+ </radialGradient>
116
+ </defs>
117
+ </svg>
frontend/src/lib/Menu.svelte CHANGED
@@ -1,7 +1,8 @@
1
  <script lang="ts">
2
  import { onMount, createEventDispatcher } from 'svelte';
3
  import PPButton from '$lib/Buttons/PPButton.svelte';
4
- import RoomsSelector from './Buttons/RoomsSelector.svelte';
 
5
  const dispatch = createEventDispatcher();
6
  export let isLoading = false;
7
  const onKeyup = (e: KeyboardEvent) => {
@@ -17,7 +18,10 @@
17
  });
18
  </script>
19
 
20
- <div class="grid grid-cols-1 gap-1 w-max mx-auto">
21
  <PPButton {isLoading} on:click={() => dispatch('prompt')} />
22
  <RoomsSelector {isLoading} />
 
 
 
23
  </div>
1
  <script lang="ts">
2
  import { onMount, createEventDispatcher } from 'svelte';
3
  import PPButton from '$lib/Buttons/PPButton.svelte';
4
+ import RoomsSelector from '$lib/Buttons/RoomsSelector.svelte';
5
+ import LiveBlocks from '$lib/Icons/LiveBlocks.svelte';
6
  const dispatch = createEventDispatcher();
7
  export let isLoading = false;
8
  const onKeyup = (e: KeyboardEvent) => {
18
  });
19
  </script>
20
 
21
+ <div class="grid grid-cols-1 gap-1 w-max mx-auto place-items-center">
22
  <PPButton {isLoading} on:click={() => dispatch('prompt')} />
23
  <RoomsSelector {isLoading} />
24
+ <a href="https://liveblocks.io" target="_blank" rel="noopener noreferrer">
25
+ <LiveBlocks />
26
+ </a>
27
  </div>
frontend/src/lib/utils.ts CHANGED
@@ -32,15 +32,12 @@ export async function uploadImage(imagBlob: Blob, prompt: string, key: string):
32
  const formData = new FormData()
33
  formData.append('file', file)
34
 
35
- console.log('uploading image', file);
36
-
37
  const response = await fetch(PUBLIC_UPLOAD_URL, {
38
  method: 'POST',
39
  body: formData
40
  });
41
  const res = await response.json();
42
 
43
- console.log('uploaded images', res);
44
  return res.filename;
45
  }
46
  const MAX = 512 * 5 - 512
32
  const formData = new FormData()
33
  formData.append('file', file)
34
 
 
 
35
  const response = await fetch(PUBLIC_UPLOAD_URL, {
36
  method: 'POST',
37
  body: formData
38
  });
39
  const res = await response.json();
40
 
 
41
  return res.filename;
42
  }
43
  const MAX = 512 * 5 - 512
frontend/src/routes/+page.svelte CHANGED
@@ -25,7 +25,7 @@
25
 
26
  // Add random id to room param if not set, and return the id string
27
  // e.g. /?room=758df70b5e94c13289df6
28
- roomId = 'multiplayer-SD';
29
 
30
  // Connect to the authentication API for Liveblocks
31
  client = createClient({
25
 
26
  // Add random id to room param if not set, and return the id string
27
  // e.g. /?room=758df70b5e94c13289df6
28
+ roomId = 'sd-multiplayer-room-0';
29
 
30
  // Connect to the authentication API for Liveblocks
31
  client = createClient({
requirements.txt CHANGED
@@ -11,4 +11,5 @@ uvicorn
11
  httpx
12
  gradio
13
  boto3
14
- python-magic
 
11
  httpx
12
  gradio
13
  boto3
14
+ python-magic
15
+ fastapi-utils
run.py CHANGED
@@ -1,4 +1,4 @@
1
  import os
2
 
3
- os.system("cd stablediffusion-infinity/PyPatchMatch && make clean && make")
4
  os.system("cd stablediffusion-infinity && python app.py")
1
  import os
2
 
3
+ os.system("cd stablediffusion-infinity/PyPatchMatch && make")
4
  os.system("cd stablediffusion-infinity && python app.py")
stablediffusion-infinity/app.py CHANGED
@@ -1,47 +1,57 @@
1
  import io
2
- import base64
3
  import os
4
  from random import sample
5
- from sched import scheduler
6
 
 
7
  import uvicorn
8
- from fastapi import FastAPI, Response, BackgroundTasks, HTTPException, UploadFile, File, status
9
  from fastapi.staticfiles import StaticFiles
10
  from fastapi.middleware.cors import CORSMiddleware
11
-
12
- import httpx
13
- from urllib.parse import urljoin
14
-
15
 
16
  import numpy as np
17
  import torch
18
  from torch import autocast
19
  from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline
20
  from PIL import Image
21
- from PIL import ImageOps
22
  import gradio as gr
23
- import base64
24
  import skimage
25
  import skimage.measure
26
  from utils import *
27
  import boto3
28
  import magic
 
 
29
 
30
  AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
31
  AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY')
32
  AWS_S3_BUCKET_NAME = os.getenv('AWS_S3_BUCKET_NAME')
 
 
 
 
 
33
 
34
  FILE_TYPES = {
35
  'image/png': 'png',
36
  'image/jpeg': 'jpg',
37
  }
 
 
38
 
39
- WHITES = 66846720
40
- MASK = Image.open("mask.png")
41
 
42
- app = FastAPI()
43
 
44
- auth_token = os.environ.get("API_TOKEN") or True
 
 
 
 
 
 
 
 
 
45
 
46
 
47
  s3 = boto3.client(service_name='s3',
@@ -63,7 +73,7 @@ def get_model():
63
  "CompVis/stable-diffusion-v1-4",
64
  revision="fp16",
65
  torch_dtype=torch.float16,
66
- use_auth_token=auth_token,
67
  ).to("cuda")
68
  inpaint = StableDiffusionInpaintPipeline(
69
  vae=text2img.vae,
@@ -103,7 +113,7 @@ def get_model():
103
  # model["img2img"]
104
 
105
 
106
- get_model()
107
 
108
 
109
  def run_outpaint(
@@ -226,20 +236,56 @@ with blocks as demo:
226
 
227
  blocks.config['dev_mode'] = False
228
 
229
- # S3_HOST = "https://s3.amazonaws.com"
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
- # @app.get("/uploads/{path:path}")
233
- # async def uploads(path: str, response: Response):
234
- # async with httpx.AsyncClient() as client:
235
- # proxy = await client.get(f"{S3_HOST}/{path}")
236
- # response.body = proxy.content
237
- # response.status_code = proxy.status_code
238
- # response.headers['Access-Control-Allow-Origin'] = '*'
239
- # response.headers['Access-Control-Allow-Methods'] = 'POST, GET, DELETE, OPTIONS'
240
- # response.headers['Access-Control-Allow-Headers'] = 'Authorization, Content-Type'
241
- # response.headers['Cache-Control'] = 'max-age=31536000'
242
- # return response
243
 
244
  @app.post('/uploadfile/')
245
  async def create_upload_file(background_tasks: BackgroundTasks, file: UploadFile):
@@ -266,9 +312,6 @@ async def create_upload_file(background_tasks: BackgroundTasks, file: UploadFile
266
  return {"url": f'https://d26smi9133w0oo.cloudfront.net/uploads/{file.filename}', "filename": file.filename}
267
 
268
 
269
- app = gr.mount_gradio_app(app, blocks, "/gradio",
270
- gradio_api_url="http://0.0.0.0:7860/gradio/")
271
-
272
  app.mount("/", StaticFiles(directory="../static", html=True), name="static")
273
 
274
  origins = ["*"]
1
  import io
 
2
  import os
3
  from random import sample
 
4
 
5
+ from pathlib import Path
6
  import uvicorn
7
+ from fastapi import FastAPI, BackgroundTasks, HTTPException, UploadFile, Depends, status
8
  from fastapi.staticfiles import StaticFiles
9
  from fastapi.middleware.cors import CORSMiddleware
10
+ from fastapi_utils.tasks import repeat_every
 
 
 
11
 
12
  import numpy as np
13
  import torch
14
  from torch import autocast
15
  from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline
16
  from PIL import Image
 
17
  import gradio as gr
 
18
  import skimage
19
  import skimage.measure
20
  from utils import *
21
  import boto3
22
  import magic
23
+ import sqlite3
24
+ import requests
25
 
26
  AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
27
  AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY')
28
  AWS_S3_BUCKET_NAME = os.getenv('AWS_S3_BUCKET_NAME')
29
+ LIVEBLOCKS_SECRET = os.environ.get("LIVEBLOCKS_SECRET")
30
+ HF_TOKEN = os.environ.get("API_TOKEN") or True
31
+
32
+ if (AWS_ACCESS_KEY_ID == None or AWS_SECRET_KEY == None or AWS_S3_BUCKET_NAME == None or LIVEBLOCKS_SECRET == None):
33
+ raise Exception("Missing environment variables")
34
 
35
  FILE_TYPES = {
36
  'image/png': 'png',
37
  'image/jpeg': 'jpg',
38
  }
39
+ DB_PATH = Path("rooms.db")
40
+ app = FastAPI()
41
 
42
+ print("DB_PATH", DB_PATH)
 
43
 
 
44
 
45
+ def get_db():
46
+ db = sqlite3.connect(DB_PATH, check_same_thread=False)
47
+ db.execute("CREATE TABLE IF NOT EXISTS rooms (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, room_id TEXT NOT NULL, users_count INTEGER NOT NULL DEFAULT 0)")
48
+ print("Connected to database")
49
+ db.commit()
50
+ db.row_factory = sqlite3.Row
51
+ try:
52
+ yield db
53
+ finally:
54
+ db.close()
55
 
56
 
57
  s3 = boto3.client(service_name='s3',
73
  "CompVis/stable-diffusion-v1-4",
74
  revision="fp16",
75
  torch_dtype=torch.float16,
76
+ use_auth_token=HF_TOKEN,
77
  ).to("cuda")
78
  inpaint = StableDiffusionInpaintPipeline(
79
  vae=text2img.vae,
113
  # model["img2img"]
114
 
115
 
116
+ # get_model()
117
 
118
 
119
  def run_outpaint(
236
 
237
  blocks.config['dev_mode'] = False
238
 
 
239
 
240
+ def generateAuthToken():
241
+ response = requests.get(f"https://liveblocks.io/api/authorize",
242
+ headers={"Authorization": f"Bearer {LIVEBLOCKS_SECRET}"})
243
+ if response.status_code == 200:
244
+ data = response.json()
245
+ return data["token"]
246
+ else:
247
+ raise Exception(response.status_code, response.text)
248
+
249
+
250
+ def get_room_count(room_id: str, jwtToken: str = ''):
251
+ print("Getting room count" + room_id)
252
+ response = requests.get(
253
+ f"https://liveblocks.net/api/v1/room/{room_id}/users", headers={"Authorization": f"Bearer {jwtToken}", "Content-Type": "application/json"})
254
+ if response.status_code == 200:
255
+ res = response.json()
256
+ if "data" in res:
257
+ return len(res["data"])
258
+ else:
259
+ return 0
260
+ raise Exception("Error getting room count")
261
+
262
+
263
+ app = gr.mount_gradio_app(app, blocks, "/gradio",
264
+ gradio_api_url="http://0.0.0.0:7860/gradio/")
265
+
266
+ app.on_event("startup")
267
+
268
+
269
+ @repeat_every(seconds=10)
270
+ async def sync_rooms(db: sqlite3.Connection = Depends(get_db)):
271
+ try:
272
+ jwtToken = generateAuthToken()
273
+ rooms = db.execute("SELECT * FROM rooms").fetchall()
274
+ print(rooms)
275
+ for row in rooms:
276
+ room_id = row["room_id"]
277
+ users_count = get_room_count(room_id, jwtToken)
278
+ print("Updating room", room_id, "with", users_count, "users")
279
+ cursor = db.cursor()
280
+ cursor.execute(
281
+ "UPDATE rooms SET users_count = ? WHERE room_id = ?", (users_count, room_id))
282
+ db.commit()
283
+ data = db.execute("SELECT * FROM rooms").fetchall()
284
+ print("Rooms updated", data)
285
+ except Exception as e:
286
+ print(e)
287
+ print("Rooms update failed")
288
 
 
 
 
 
 
 
 
 
 
 
 
289
 
290
  @app.post('/uploadfile/')
291
  async def create_upload_file(background_tasks: BackgroundTasks, file: UploadFile):
312
  return {"url": f'https://d26smi9133w0oo.cloudfront.net/uploads/{file.filename}', "filename": file.filename}
313
 
314
 
 
 
 
315
  app.mount("/", StaticFiles(directory="../static", html=True), name="static")
316
 
317
  origins = ["*"]