q6 commited on
Commit
2a31992
·
1 Parent(s): 62c6f7a

Use-GPU-for-diffusion-ping

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -111,6 +111,7 @@ DEFAULT_UI_BATCH_SIZE = 1
111
  MAX_BATCH_SIZE = 8
112
  PING_MODEL_ID = 50
113
  PING_SIZE = 64
 
114
  PING_SAMPLER = "euler"
115
  PING_SCHEDULER = "simple"
116
  STARTUP_ASSET_IDS = {
@@ -1230,6 +1231,7 @@ def infer_image(
1230
  return image
1231
 
1232
 
 
1233
  def infer_ping(model_name):
1234
  with torch.inference_mode():
1235
  model, clip = load_chain(model_name, [])
@@ -1239,21 +1241,22 @@ def infer_ping(model_name):
1239
  height=PING_SIZE,
1240
  batch_size=1,
1241
  )[0]
1242
- conditioning = state["encode"].encode(clip=clip, text="")[0]
 
1243
  samples = run_sampler(
1244
  model,
1245
  secrets.randbits(64),
1246
- 1,
1247
  1,
1248
  PING_SAMPLER,
1249
  PING_SCHEDULER,
1250
- conditioning,
1251
- conditioning,
1252
  latent,
1253
  1,
1254
  )
1255
  image = state["decode"].decode(vae=vae, samples=samples)[0]
1256
- return tensor_image(image).resize((1, 1), Image.Resampling.LANCZOS)
1257
 
1258
 
1259
  def generate_gpu(request, regions, style_image, second_style_image):
 
111
  MAX_BATCH_SIZE = 8
112
  PING_MODEL_ID = 50
113
  PING_SIZE = 64
114
+ PING_STEPS = 8
115
  PING_SAMPLER = "euler"
116
  PING_SCHEDULER = "simple"
117
  STARTUP_ASSET_IDS = {
 
1231
  return image
1232
 
1233
 
1234
+ @spaces.GPU(duration=3)
1235
  def infer_ping(model_name):
1236
  with torch.inference_mode():
1237
  model, clip = load_chain(model_name, [])
 
1241
  height=PING_SIZE,
1242
  batch_size=1,
1243
  )[0]
1244
+ positive = state["encode"].encode(clip=clip, text="1girl")[0]
1245
+ negative = state["encode"].encode(clip=clip, text="")[0]
1246
  samples = run_sampler(
1247
  model,
1248
  secrets.randbits(64),
1249
+ PING_STEPS,
1250
  1,
1251
  PING_SAMPLER,
1252
  PING_SCHEDULER,
1253
+ positive,
1254
+ negative,
1255
  latent,
1256
  1,
1257
  )
1258
  image = state["decode"].decode(vae=vae, samples=samples)[0]
1259
+ return tensor_image(image)
1260
 
1261
 
1262
  def generate_gpu(request, regions, style_image, second_style_image):