Spaces:
Running
Running
File size: 665 Bytes
01488bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 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;
}
|