avans06 commited on
Commit
624fa8c
·
1 Parent(s): 2f1b118

The wd-tagger-images can now correctly handle duplicate image names.

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -12,8 +12,9 @@ import tempfile
12
  import zipfile
13
  import re
14
  from datetime import datetime
 
15
 
16
- TITLE = "WaifuDiffusion Tagger"
17
  DESCRIPTION = """
18
  Demo for the WaifuDiffusion tagger models
19
 
@@ -372,11 +373,18 @@ class Predictor:
372
  if prepend_list and append_list:
373
  append_list = [item for item in append_list if item not in prepend_list]
374
 
 
 
375
  for idx, value in enumerate(gallery):
376
  try:
377
  image_path = value[0]
378
  image_name = os.path.splitext(os.path.basename(image_path))[0]
379
 
 
 
 
 
 
380
  image = self.prepare_image(image_path)
381
 
382
  input_name = self.model.get_inputs()[0].name
 
12
  import zipfile
13
  import re
14
  from datetime import datetime
15
+ from collections import defaultdict
16
 
17
+ TITLE = "WaifuDiffusion Tagger multiple images"
18
  DESCRIPTION = """
19
  Demo for the WaifuDiffusion tagger models
20
 
 
373
  if prepend_list and append_list:
374
  append_list = [item for item in append_list if item not in prepend_list]
375
 
376
+ # Dictionary to track counters for each filename
377
+ name_counters = defaultdict(int)
378
  for idx, value in enumerate(gallery):
379
  try:
380
  image_path = value[0]
381
  image_name = os.path.splitext(os.path.basename(image_path))[0]
382
 
383
+ # Increment the counter for the current name
384
+ name_counters[image_name] += 1
385
+ if name_counters[image_name] > 1:
386
+ image_name = f"{image_name}_{name_counters[image_name]:02d}"
387
+
388
  image = self.prepare_image(image_path)
389
 
390
  input_name = self.model.get_inputs()[0].name