fix(routes): await trained words extraction

This commit is contained in:
pixelpaws
2025-10-03 22:45:25 +08:00
parent 40e3c6134c
commit 2d37a7341a

View File

@@ -320,9 +320,14 @@ class TrainedWordsHandler:
if not file_path.endswith(".safetensors"): if not file_path.endswith(".safetensors"):
return web.json_response({"success": False, "error": "File must be a safetensors file"}, status=400) return web.json_response({"success": False, "error": "File must be a safetensors file"}, status=400)
trained_words = extract_trained_words(file_path) trained_words, class_tokens = await extract_trained_words(file_path)
sorted_words = sorted(trained_words, key=lambda w: w.get("count", 0), reverse=True) return web.json_response(
return web.json_response({"success": True, "trained_words": sorted_words}) {
"success": True,
"trained_words": trained_words,
"class_tokens": class_tokens,
}
)
except Exception as exc: # pragma: no cover - defensive logging except Exception as exc: # pragma: no cover - defensive logging
logger.error("Failed to get trained words: %s", exc, exc_info=True) logger.error("Failed to get trained words: %s", exc, exc_info=True)
return web.json_response({"success": False, "error": str(exc)}, status=500) return web.json_response({"success": False, "error": str(exc)}, status=500)