Add optional save prompt to txt with image name when exporting favorites

This commit is contained in:
JasonHoku
2026-02-16 22:09:35 -08:00
parent 7d9fee69d0
commit 5f652b813d
3 changed files with 30 additions and 1 deletions
+15
View File
@@ -353,6 +353,7 @@ async def export_favorites(request):
pack_metadata = data.get("pack_metadata", False)
organize_by_prompt = data.get("organize_by_prompt", False)
organize_by_lora = data.get("organize_by_lora", False)
export_prompt_txt = data.get("export_prompt_txt", False)
# Sanitize
if session_name:
@@ -494,6 +495,18 @@ async def export_favorites(request):
else:
shutil.copy2(source_path, dest_path)
exported_count += 1
# Export positive prompt as .txt file alongside the image
if export_prompt_txt:
try:
prompt_text = item.get("positive") or manifest.get("meta", {}).get("positive", "")
if prompt_text:
txt_filename = os.path.splitext(dest_filename)[0] + '.txt'
txt_path = os.path.join(dest_dir, txt_filename)
with open(txt_path, "w", encoding="utf-8") as txt_file:
txt_file.write(prompt_text)
except Exception as e:
print(f"[Export] Error writing prompt txt for {filename}: {e}")
result_msg = f"Exported {exported_count} favorited images to 'benchmarks/{session_name}/favorites/'"
if organize_by_prompt and organize_by_lora:
@@ -504,6 +517,8 @@ async def export_favorites(request):
result_msg += f" (organized into {len(lora_to_folder)} lora folders)"
if pack_metadata:
result_msg += " (with metadata packed)"
if export_prompt_txt:
result_msg += " (with prompt .txt files)"
print(f"[ConfigTester] ✅ {result_msg}")
return web.Response(status=200, text=result_msg)
+6 -1
View File
@@ -168,6 +168,10 @@ async function exportFavorites() {
const organizeLoraCheckbox = document.getElementById('organize-by-lora-checkbox');
const organizeByLora = organizeLoraCheckbox ? organizeLoraCheckbox.checked : false;
// Get export prompt txt checkbox state
const promptTxtCheckbox = document.getElementById('export-prompt-txt-checkbox');
const exportPromptTxt = promptTxtCheckbox ? promptTxtCheckbox.checked : false;
// Show loading state
if (statusEl) {
statusEl.innerText = '⏳ Exporting favorites...';
@@ -187,7 +191,8 @@ async function exportFavorites() {
session_name: sessionName,
pack_metadata: packMetadata,
organize_by_prompt: organizeByPrompt,
organize_by_lora: organizeByLora
organize_by_lora: organizeByLora,
export_prompt_txt: exportPromptTxt
})
});
+9
View File
@@ -130,6 +130,15 @@
</label>
</div>
<div style="margin-top: 8px; display: flex; align-items: center; gap: 6px;">
<input type="checkbox" id="export-prompt-txt-checkbox"
style="width: 14px; height: 14px; cursor: pointer;">
<label for="export-prompt-txt-checkbox"
style="font-size: 10px; color: #999; cursor: pointer; user-select: none;">
Export positive prompt as .txt file alongside each image
</label>
</div>
<div id="export-status" style="margin-top: 8px; font-size: 10px; color: #666; min-height: 16px;"></div>
</div>