CristianLazoQuispe commited on
Commit
fc76090
·
1 Parent(s): f870389

continous streaming generation

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -9,7 +9,7 @@ from src.model import ConditionalUNet
9
  from huggingface_hub import hf_hub_download
10
  import time
11
  device = 'cuda:0' if torch.cuda.is_available() else 'cpu'
12
- device = 'cpu'
13
  img_shape = (1, 28, 28)
14
 
15
 
@@ -73,13 +73,20 @@ def generate_diffusion_intermediates_streaming(label):
73
  outputs[step_idx] = resize(vel_colored)
74
  yield tuple(outputs)
75
 
 
 
76
  if t in [400, 300, 200, 100, 1, 0]:
77
  step_idx = {400: 1, 300: 2, 200: 3, 100: 4, 1: 5, 0 :12}[t]
78
  if t==0:
79
- outputs[step_idx] = resize(((x + 1) / 2.0)[0, 0].cpu().numpy(),(400,400))
80
  else:
81
  outputs[step_idx] = resize(((x + 1) / 2.0)[0, 0].cpu().numpy())
82
  yield tuple(outputs)
 
 
 
 
 
83
 
84
 
85
  def generate_localized_noise(shape, radius=5):
@@ -127,9 +134,9 @@ def generate_flow_intermediates_streaming(label):
127
  v = model_flow(x, t, y)
128
  x = x + v * dt
129
 
130
- if i in [10,20,30,40,48,49]:
131
- #images.append((x + 1) / 2.0)
132
- step_idx = {10: 1, 20: 2, 30: 3, 40: 4, 48: 5, 49:12}[i]
133
  if i==49:
134
  outputs[step_idx] = resize(((x + 1) / 2.0)[0, 0].clamp(0, 1).cpu().numpy(),(300,300))
135
  else:
@@ -146,6 +153,12 @@ def generate_flow_intermediates_streaming(label):
146
  step_idx = {0: 6, 11: 7, 21: 8, 31: 9, 41: 10, 49:11}[i]
147
  outputs[step_idx] = resize(vel_colored)
148
  yield tuple(outputs)
 
 
 
 
 
 
149
 
150
 
151
  with gr.Blocks() as demo:
@@ -207,5 +220,5 @@ with gr.Blocks() as demo:
207
  ]
208
  btn_f.click(fn=generate_flow_intermediates_streaming, inputs=label_f, outputs=outs_f+flow_vel_imgs+flow_result_imgs)
209
 
210
- #demo.launch()
211
- demo.launch(share=False, server_port=9071)
 
9
  from huggingface_hub import hf_hub_download
10
  import time
11
  device = 'cuda:0' if torch.cuda.is_available() else 'cpu'
12
+ #device = 'cpu'
13
  img_shape = (1, 28, 28)
14
 
15
 
 
73
  outputs[step_idx] = resize(vel_colored)
74
  yield tuple(outputs)
75
 
76
+ outputs[12] = resize(((x + 1) / 2.0)[0, 0].cpu().numpy(),(300,300))
77
+
78
  if t in [400, 300, 200, 100, 1, 0]:
79
  step_idx = {400: 1, 300: 2, 200: 3, 100: 4, 1: 5, 0 :12}[t]
80
  if t==0:
81
+ outputs[step_idx] = resize(((x + 1) / 2.0)[0, 0].cpu().numpy(),(300,300))
82
  else:
83
  outputs[step_idx] = resize(((x + 1) / 2.0)[0, 0].cpu().numpy())
84
  yield tuple(outputs)
85
+ if t % 10 == 0:
86
+ yield tuple(outputs)
87
+ time.sleep(0.05)
88
+ #time.sleep(0.1)
89
+ yield tuple(outputs)
90
 
91
 
92
  def generate_localized_noise(shape, radius=5):
 
134
  v = model_flow(x, t, y)
135
  x = x + v * dt
136
 
137
+ outputs[12] = resize(((x + 1) / 2.0)[0, 0].clamp(0, 1).cpu().numpy(),(300,300))
138
+ if i in [10,20,30,40,48,49]: #
139
+ step_idx = {10: 1, 20: 2, 30: 3, 40: 4, 48: 5,49:12}[i] #,
140
  if i==49:
141
  outputs[step_idx] = resize(((x + 1) / 2.0)[0, 0].clamp(0, 1).cpu().numpy(),(300,300))
142
  else:
 
153
  step_idx = {0: 6, 11: 7, 21: 8, 31: 9, 41: 10, 49:11}[i]
154
  outputs[step_idx] = resize(vel_colored)
155
  yield tuple(outputs)
156
+ if t % 10 == 0:
157
+ yield tuple(outputs)
158
+ time.sleep(0.05)
159
+
160
+ #time.sleep(0.1)
161
+ yield tuple(outputs)
162
 
163
 
164
  with gr.Blocks() as demo:
 
220
  ]
221
  btn_f.click(fn=generate_flow_intermediates_streaming, inputs=label_f, outputs=outs_f+flow_vel_imgs+flow_result_imgs)
222
 
223
+ demo.launch()
224
+ #demo.launch(share=False, server_port=9071)