LFM2-VL-WebGPU / src /context /VLMContext.ts
mlabonne's picture
upload demo files (#1)
01488bc
raw
history blame contribute delete
665 Bytes
import { createContext, useContext } from "react";
export type LoadState = {
error: string | null;
message: string;
progress: number;
status: "idle" | "loading" | "ready" | "error";
};
export type VLMContextValue = LoadState & {
generateCaption: (request: {
frame: ImageData;
onStream?: (text: string) => void;
prompt: string;
}) => Promise<string>;
loadModel: () => Promise<void>;
};
export const VLMContext = createContext<VLMContextValue | null>(null);
export function useVLM() {
const context = useContext(VLMContext);
if (!context) {
throw new Error("useVLM must be used within a VLMProvider.");
}
return context;
}