drscotthawley commited on
Commit
1b4c6b5
1 Parent(s): afe19a7

trying new subprocess thing

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -35,8 +35,6 @@ from sample import zero_wrapper
35
  from pom.pianoroll import regroup_lines, img_file_2_midi_file, square_to_rect, rect_to_square
36
  from pom.square_to_rect import square_to_rect
37
 
38
- zero = torch.Tensor([0]).cuda() # used for gpu checking later
39
- accelerator = accelerate.Accelerator()
40
 
41
  CT_HOME = '.'
42
 
@@ -114,11 +112,6 @@ class Args:
114
  @spaces.GPU
115
  def process_image(image, repaint, busyness):
116
 
117
- print("CUDA check:")
118
- print(" zero.device = ",zero.device)
119
- device = accelerator.device
120
- print(' accelerator.device:', device, flush=True)
121
-
122
  # get image ready and execute sampler
123
  print("image = ",image)
124
  image = image['composite']
@@ -140,17 +133,24 @@ def process_image(image, repaint, busyness):
140
  PREFIX = 'gradiodemo'
141
  # !echo {DEVICES} {CT_HOME} {CKPT} {PREFIX} {masked_img_file}
142
  print("Reading init image from ", masked_img_file,", repaint = ",repaint)
143
- # Commenting out the following since HF ZeroGPU doesn't seem to work with subprocesses.
144
- # cmd = f'{sys.executable} {CT_HOME}/sample.py --batch-size {bs} --checkpoint {CKPT} --config {CT_HOME}/configs/config_pop909_256x256_chords.json -n {num} --prefix {PREFIX} --init-image {masked_img_file} --steps=100 --repaint={repaint}'
145
- # print("Will run command: ", cmd)
146
- # args = cmd.split(' ')
147
- # #call(cmd, shell=True)
148
- # print("Calling: ", args,"\n")
149
- # return_value = call(args)
150
- # print("Return value = ", return_value)
151
- args = Args(batch_size=bs, checkpoint=CKPT, config=f'{CT_HOME}/configs/config_pop909_256x256_chords.json', n=num, prefix=PREFIX, init_image=masked_img_file, steps=100, seed_scale=0.0, repaint=repaint)
152
- print(" Now calling zero_wrapper with args = ",args,"\n")
153
- zero_wrapper(args, accelerator, device)
 
 
 
 
 
 
 
154
 
155
  # find gen'd image and convert to midi piano roll
156
  #gen_file = f'{PREFIX}_00000.png'
 
35
  from pom.pianoroll import regroup_lines, img_file_2_midi_file, square_to_rect, rect_to_square
36
  from pom.square_to_rect import square_to_rect
37
 
 
 
38
 
39
  CT_HOME = '.'
40
 
 
112
  @spaces.GPU
113
  def process_image(image, repaint, busyness):
114
 
 
 
 
 
 
115
  # get image ready and execute sampler
116
  print("image = ",image)
117
  image = image['composite']
 
133
  PREFIX = 'gradiodemo'
134
  # !echo {DEVICES} {CT_HOME} {CKPT} {PREFIX} {masked_img_file}
135
  print("Reading init image from ", masked_img_file,", repaint = ",repaint)
136
+
137
+ # HF ZeroGPU+Gradio doesn't seem to work with subprocesses.
138
+ use_subprocess = True
139
+ if use_subprocess:
140
+ cmd = f'{sys.executable} {CT_HOME}/sample.py --batch-size {bs} --checkpoint {CKPT} --config {CT_HOME}/configs/config_pop909_256x256_chords.json -n {num} --prefix {PREFIX} --init-image {masked_img_file} --steps=100 --repaint={repaint}'
141
+ print("Will run command: ", cmd)
142
+ args = cmd.split(' ')
143
+ #call(cmd, shell=True)
144
+ print("Calling subprocess with args = ", args,"\n")
145
+ return_value = call(args)
146
+ print("Subprocess finished. Return value = ", return_value)
147
+ else:
148
+ accelerator = accelerate.Accelerator()
149
+ device = accelerator.device
150
+ print("Accelerator device = ", device)
151
+ args = Args(batch_size=bs, checkpoint=CKPT, config=f'{CT_HOME}/configs/config_pop909_256x256_chords.json', n=num, prefix=PREFIX, init_image=masked_img_file, steps=100, seed_scale=0.0, repaint=repaint)
152
+ print(" Now calling zero_wrapper with args = ",args,"\n")
153
+ zero_wrapper(args, accelerator, device)
154
 
155
  # find gen'd image and convert to midi piano roll
156
  #gen_file = f'{PREFIX}_00000.png'