web-llm icon indicating copy to clipboard operation
web-llm copied to clipboard

Phi-3.5-vision-instruct-q4f16_1-MLC

Open raulgupta opened this issue 1 year ago • 7 comments

Screenshot 2024-11-27 at 1 00 28 AM

raulgupta avatar Nov 27 '24 09:11 raulgupta

`// WebLLM Import
import * as webllm from "https://esm.run/@mlc-ai/web-llm";
window.webllm = webllm;

// Engine Initialization
const initializeEngine = async () => {
    try {
        setInitStatus("Initializing WebLLM engine...");
        const webllm = window.webllm;
        const newEngine = await webllm.CreateMLCEngine(
            "Phi-3.5-vision-instruct-q4f16_1-MLC",
            {
                initProgressCallback: (report) => setInitStatus(report.text),
                logLevel: "INFO"
            },
            { context_window_size: 6144 }
        );
        setEngine(newEngine);
        setInitStatus("Engine ready!");
    } catch (error) {
        setInitStatus("Failed to initialize engine: " + error.message);
        console.error("Engine initialization error:", error);
    }
};

// Image Analysis Function
const handleAnalyze = async () => {
    if (!engine) {
        setAnalysis("Engine not initialized. Please wait...");
        return;
    }

    try {
        setIsAnalyzing(true);
        setAnalysis("Converting image...");
        
        const base64Image = await fileToBase64(file);
        
        setAnalysis("Analyzing image...");
        const request = {
            stream: false,
            messages: [{
                role: "user",
                content: [
                    { type: "text", text: "What's in this image? Describe it in detail." },
                    {
                        type: "image_url",
                        image_url: { url: base64Image }
                    }
                ]
            }]
        };

        const reply = await engine.chat.completions.create(request);
        const message = await engine.getMessage();
        setAnalysis(message);
    } catch (error) {
        setAnalysis("Error analyzing image: " + error.message);
        console.error("Analysis error:", error);
    } finally {
        setIsAnalyzing(false);
    }
};

// WebGPU Support Check
async function checkSystem() {
    if ('gpu' in navigator) {
        const adapter = await navigator.gpu.requestAdapter();
        if (adapter) {
            gpuInfoEl.textContent = adapter.name || 'WebGPU Ready';
            gpuDetailEl.textContent = 'WebGPU Supported';
        } else {
            gpuInfoEl.textContent = 'No WebGPU Adapter';
            gpuDetailEl.textContent = 'Hardware acceleration unavailable';
        }
    } else {
        gpuInfoEl.textContent = 'WebGPU Not Supported';
        gpuDetailEl.textContent = 'Browser does not support WebGPU';
    }
}`

raulgupta avatar Nov 27 '24 09:11 raulgupta

yes it is not working.

djaffer avatar Dec 02 '24 06:12 djaffer

Getting this error too, not sure what's the cause

numinousmuses avatar Jan 03 '25 23:01 numinousmuses

Any progress on this issue? The error is also present in the examples/vision-model example.

jakobhoeg avatar Jan 21 '25 12:01 jakobhoeg

Once HuggingFace has its transformer js documentation improved that might be a viable alternative and simpler to use. They support using quantized models too.

djaffer avatar Jan 26 '25 04:01 djaffer

Any updates?

gornostay25 avatar Mar 22 '25 12:03 gornostay25

Any updates?

InfTkm avatar May 31 '25 17:05 InfTkm