Spaces:
Running
Running
| 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; | |
| } | |