k-l-lambda commited on
Commit
7511f27
1 Parent(s): 9933c91

app.py: cached uploaded images.

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -218,6 +218,21 @@ def load_example (face_file, pose_file, prompt, style, negative_prompt):
218
  return image, gr.update(visible=True)
219
 
220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  def generate_image (
222
  novita_key1,
223
  model_name,
@@ -274,13 +289,15 @@ def generate_image (
274
  CONTROLNET_DICT['canny']['strength'] = canny_strength
275
  CONTROLNET_DICT['depth']['strength'] = depth_strength
276
 
 
 
277
  res = client._post('/v3/async/instant-id', {
278
  'extra': {
279
  'response_image_type': 'jpeg',
280
  },
281
  'model_name': f'{model_name}.safetensors',
282
- 'face_image_assets_ids': client.upload_assets([face_image_path]),
283
- 'ref_image_assets_ids': client.upload_assets([ref_image_path]),
284
  'prompt': prompt,
285
  'negative_prompt': negative_prompt,
286
  'controlnet': {
 
218
  return image, gr.update(visible=True)
219
 
220
 
221
+ upload_depot = {}
222
+
223
+ def upload_assets_with_cache (client, paths):
224
+ global upload_depot
225
+
226
+ pending_paths = [path for path in paths if not path in upload_depot]
227
+ if pending_paths:
228
+ print('uploading images:', pending_paths)
229
+ for key, value in zip(pending_paths, client.upload_assets(pending_paths)):
230
+ upload_depot[key] = value
231
+
232
+ return [upload_depot[path] for path in paths]
233
+
234
+
235
+
236
  def generate_image (
237
  novita_key1,
238
  model_name,
 
289
  CONTROLNET_DICT['canny']['strength'] = canny_strength
290
  CONTROLNET_DICT['depth']['strength'] = depth_strength
291
 
292
+ face_image_uploaded, ref_image_uploaded = upload_assets_with_cache(client, [face_image_path, ref_image_path])
293
+
294
  res = client._post('/v3/async/instant-id', {
295
  'extra': {
296
  'response_image_type': 'jpeg',
297
  },
298
  'model_name': f'{model_name}.safetensors',
299
+ 'face_image_assets_ids': [face_image_uploaded],
300
+ 'ref_image_assets_ids': [ref_image_uploaded],
301
  'prompt': prompt,
302
  'negative_prompt': negative_prompt,
303
  'controlnet': {