@blank-utils/llm 0.4.14 → 0.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -915,24 +915,27 @@ function ChatInput({
|
|
|
915
915
|
const textareaRef = useRef2(null);
|
|
916
916
|
const fileInputRef = useRef2(null);
|
|
917
917
|
const [isDragging, setIsDragging] = useState2(false);
|
|
918
|
-
const
|
|
918
|
+
const captionerPromiseRef = useRef2(null);
|
|
919
919
|
useEffect2(() => {
|
|
920
920
|
let mounted = true;
|
|
921
|
+
if (captionerPromiseRef.current) return;
|
|
921
922
|
const initCaptioner = async () => {
|
|
922
923
|
try {
|
|
924
|
+
console.log("[ImagePipeline] Initializing Transformers.js background captioner...");
|
|
923
925
|
const { pipeline: pipeline2, env } = await import("@huggingface/transformers");
|
|
924
926
|
env.allowLocalModels = false;
|
|
925
927
|
env.useBrowserCache = true;
|
|
926
928
|
const captioner = await pipeline2("image-to-text", "Xenova/vit-gpt2-image-captioning", {
|
|
927
|
-
device: "wasm"
|
|
928
|
-
dtype: "q8"
|
|
929
|
+
device: "wasm"
|
|
929
930
|
});
|
|
930
|
-
if (mounted)
|
|
931
|
+
if (mounted) console.log("[ImagePipeline] Captioner loaded successfully!");
|
|
932
|
+
return captioner;
|
|
931
933
|
} catch (err) {
|
|
932
934
|
console.warn("Failed to initialize background captioner:", err);
|
|
935
|
+
return null;
|
|
933
936
|
}
|
|
934
937
|
};
|
|
935
|
-
initCaptioner();
|
|
938
|
+
captionerPromiseRef.current = initCaptioner();
|
|
936
939
|
return () => {
|
|
937
940
|
mounted = false;
|
|
938
941
|
};
|
|
@@ -1055,17 +1058,27 @@ ${newText}` : newText);
|
|
|
1055
1058
|
const id = Math.random().toString(36).substring(7);
|
|
1056
1059
|
const dataUrl = e.target.result;
|
|
1057
1060
|
let extractedText;
|
|
1058
|
-
if (
|
|
1061
|
+
if (captionerPromiseRef.current) {
|
|
1062
|
+
console.log(`[ImagePipeline] Generating caption for ${file.name} (Waiting for captioner)...`);
|
|
1059
1063
|
try {
|
|
1060
|
-
const
|
|
1061
|
-
if (
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1064
|
+
const captioner = await captionerPromiseRef.current;
|
|
1065
|
+
if (captioner) {
|
|
1066
|
+
const out = await captioner(dataUrl);
|
|
1067
|
+
console.log("[ImagePipeline] Raw captioner output:", out);
|
|
1068
|
+
if (Array.isArray(out) && out[0] && out[0].generated_text) {
|
|
1069
|
+
extractedText = out[0].generated_text;
|
|
1070
|
+
} else if (!Array.isArray(out) && out.generated_text) {
|
|
1071
|
+
extractedText = out.generated_text;
|
|
1072
|
+
}
|
|
1073
|
+
console.log("[ImagePipeline] Extracted caption text:", extractedText);
|
|
1074
|
+
} else {
|
|
1075
|
+
console.log("[ImagePipeline] Captioner initialized to null, skipping caption generation.");
|
|
1065
1076
|
}
|
|
1066
1077
|
} catch (err) {
|
|
1067
|
-
console.warn("Background captioning failed for image:", err);
|
|
1078
|
+
console.warn("[ImagePipeline] Background captioning failed for image:", err);
|
|
1068
1079
|
}
|
|
1080
|
+
} else {
|
|
1081
|
+
console.log("[ImagePipeline] Captioner promise ref is null, skipping caption generation.");
|
|
1069
1082
|
}
|
|
1070
1083
|
onImageAdd?.({ id, dataUrl, file, name: file.name, extractedText });
|
|
1071
1084
|
}
|
package/dist/index.js
CHANGED
package/dist/react/index.js
CHANGED
package/package.json
CHANGED