ura23 commited on
Commit
62a3f36
·
verified ·
1 Parent(s): f05d102

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -26
app.py CHANGED
@@ -220,25 +220,19 @@ def main():
220
  with gr.Column():
221
  output = gr.Textbox(label="Output", lines=10)
222
 
223
- def process_images(files, model_repo, general_thresh, character_thresh, filter_tags, custom_tags):
224
  images = [Image.open(file.name) for file in files]
225
  results = predictor.predict(images, model_repo, general_thresh, character_thresh)
226
 
227
  # Parse filter tags
228
  filter_set = set(tag.strip().lower() for tag in filter_tags.split(","))
229
-
230
- # Parse custom tags
231
- custom_tag_list = [tag.strip().lower() for tag in custom_tags.split(",")]
232
-
233
- # Define the fallback tags for each custom tag
234
- fallback_tags = {
235
- "shy, happy": "smile",
236
- "happy": "joy",
237
- "cute": "adorable",
238
- "energetic": "vibrant",
239
- "blush": "flushed",
240
- # Add more custom to fallback mappings as needed
241
- }
242
 
243
  # Generate formatted output
244
  prompts = []
@@ -251,22 +245,20 @@ def main():
251
  tag.replace('_', ' ') for tag in general_tags if tag.lower() not in filter_set
252
  )
253
 
254
- # Check for missing custom tags and apply corresponding fallback tags
255
- for custom_tag in custom_tag_list:
256
- if custom_tag not in (general_tags + character_tags):
257
- # Append the corresponding fallback tag for the missing custom tag
258
- if custom_tag in fallback_tags:
259
- general_part += ", " + fallback_tags[custom_tag]
260
-
261
- # Construct the prompt based on the presence of character_part
262
- if character_part:
263
- prompts.append(f"{character_part}, {general_part}")
264
- else:
265
- prompts.append(general_part)
266
 
267
  # Join all prompts with blank lines
268
  return "\n\n".join(prompts)
269
 
 
270
  submit.click(
271
  process_images,
272
  inputs=[image_files, model_repo, general_thresh, character_thresh, filter_tags, custom_tags],
 
220
  with gr.Column():
221
  output = gr.Textbox(label="Output", lines=10)
222
 
223
+ def process_images(files, model_repo, general_thresh, character_thresh, filter_tags, custom_tags_input):
224
  images = [Image.open(file.name) for file in files]
225
  results = predictor.predict(images, model_repo, general_thresh, character_thresh)
226
 
227
  # Parse filter tags
228
  filter_set = set(tag.strip().lower() for tag in filter_tags.split(","))
229
+
230
+ # Parse custom tags and their fallback pairs
231
+ fallback_tags = {}
232
+ for pair in custom_tags_input.split(","):
233
+ if ":" in pair:
234
+ tag, fallback = pair.split(":")
235
+ fallback_tags[tag.strip().lower()] = fallback.strip().lower()
 
 
 
 
 
 
236
 
237
  # Generate formatted output
238
  prompts = []
 
245
  tag.replace('_', ' ') for tag in general_tags if tag.lower() not in filter_set
246
  )
247
 
248
+ # Check if custom tags are missing and apply fallback tags
249
+ all_tags = set(general_tags + character_tags)
250
+ for tag, fallback in fallback_tags.items():
251
+ if tag not in all_tags:
252
+ all_tags.add(fallback)
253
+
254
+ # Construct the final prompt
255
+ final_tags = ", ".join(tag.replace('_', ' ') for tag in all_tags if tag.lower() not in filter_set)
256
+ prompts.append(final_tags)
 
 
 
257
 
258
  # Join all prompts with blank lines
259
  return "\n\n".join(prompts)
260
 
261
+
262
  submit.click(
263
  process_images,
264
  inputs=[image_files, model_repo, general_thresh, character_thresh, filter_tags, custom_tags],