Spaces:
Running
Running
Update app.py
Browse files
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,
|
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 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
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
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
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],
|