Spaces:
Running
on
Zero
Running
on
Zero
drscotthawley
commited on
Commit
•
59a2caa
1
Parent(s):
5224929
adding zero gpu tags
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
# imports from gradio_demo.py
|
2 |
import gradio as gr
|
|
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
import torch
|
@@ -24,12 +25,16 @@ from tqdm import trange, tqdm
|
|
24 |
from torchvision import transforms
|
25 |
import k_diffusion as K
|
26 |
|
|
|
|
|
|
|
27 |
|
28 |
from pom.pianoroll import regroup_lines, img_file_2_midi_file, square_to_rect, rect_to_square
|
29 |
from pom.square_to_rect import square_to_rect
|
30 |
|
31 |
CT_HOME = '.'
|
32 |
|
|
|
33 |
def infer_mask_from_init_img(img, mask_with='grey'):
|
34 |
"note, this works whether image is normalized on 0..1 or -1..1, but not 0..255"
|
35 |
assert mask_with in ['blue','white','grey']
|
@@ -52,6 +57,7 @@ def infer_mask_from_init_img(img, mask_with='grey'):
|
|
52 |
return mask*1.0
|
53 |
|
54 |
|
|
|
55 |
def count_notes_in_mask(img, mask):
|
56 |
"counts the number of new notes in the mask"
|
57 |
img_t = ToTensor()(img)
|
@@ -59,6 +65,7 @@ def count_notes_in_mask(img, mask):
|
|
59 |
return new_notes.item()
|
60 |
|
61 |
|
|
|
62 |
def grab_dense_gen(init_img,
|
63 |
PREFIX,
|
64 |
num_to_gen=64,
|
@@ -85,8 +92,9 @@ def grab_dense_gen(init_img,
|
|
85 |
return dense_filename
|
86 |
|
87 |
|
88 |
-
|
89 |
def process_image(image, repaint, busyness):
|
|
|
90 |
# get image ready and execute sampler
|
91 |
print("image = ",image)
|
92 |
image = image['composite']
|
@@ -136,11 +144,6 @@ def process_image(image, repaint, busyness):
|
|
136 |
|
137 |
return gen_image, html, audio_file
|
138 |
|
139 |
-
# def greet(name):
|
140 |
-
# return "Hello " + name + "!!"
|
141 |
-
|
142 |
-
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
143 |
-
# demo.launch()
|
144 |
|
145 |
|
146 |
make_dict = lambda x: {'background':x, 'composite':x, 'layers':[x]}
|
|
|
1 |
# imports from gradio_demo.py
|
2 |
import gradio as gr
|
3 |
+
import spaces
|
4 |
import numpy as np
|
5 |
from PIL import Image
|
6 |
import torch
|
|
|
25 |
from torchvision import transforms
|
26 |
import k_diffusion as K
|
27 |
|
28 |
+
zero = torch.Tensor([0]).cuda()
|
29 |
+
print("Zero Device = ",zero.device," <-- this probably says cpu") # <-- 'cpu' 🤔
|
30 |
+
|
31 |
|
32 |
from pom.pianoroll import regroup_lines, img_file_2_midi_file, square_to_rect, rect_to_square
|
33 |
from pom.square_to_rect import square_to_rect
|
34 |
|
35 |
CT_HOME = '.'
|
36 |
|
37 |
+
@spaces.GPU
|
38 |
def infer_mask_from_init_img(img, mask_with='grey'):
|
39 |
"note, this works whether image is normalized on 0..1 or -1..1, but not 0..255"
|
40 |
assert mask_with in ['blue','white','grey']
|
|
|
57 |
return mask*1.0
|
58 |
|
59 |
|
60 |
+
@spaces.GPU
|
61 |
def count_notes_in_mask(img, mask):
|
62 |
"counts the number of new notes in the mask"
|
63 |
img_t = ToTensor()(img)
|
|
|
65 |
return new_notes.item()
|
66 |
|
67 |
|
68 |
+
@spaces.GPU
|
69 |
def grab_dense_gen(init_img,
|
70 |
PREFIX,
|
71 |
num_to_gen=64,
|
|
|
92 |
return dense_filename
|
93 |
|
94 |
|
95 |
+
@spaces.GPU
|
96 |
def process_image(image, repaint, busyness):
|
97 |
+
print("Process Image: Zero Device = ",zero.device)
|
98 |
# get image ready and execute sampler
|
99 |
print("image = ",image)
|
100 |
image = image['composite']
|
|
|
144 |
|
145 |
return gen_image, html, audio_file
|
146 |
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
|
149 |
make_dict = lambda x: {'background':x, 'composite':x, 'layers':[x]}
|