Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phi-3.5-vision-instruct-q4f16_1-MLC #640

Open
raulgupta opened this issue Nov 27, 2024 · 2 comments
Open

Phi-3.5-vision-instruct-q4f16_1-MLC #640

raulgupta opened this issue Nov 27, 2024 · 2 comments

Comments

@raulgupta
Copy link

raulgupta commented Nov 27, 2024

Screenshot 2024-11-27 at 1 00 28 AM
@raulgupta
Copy link
Author

raulgupta commented Nov 27, 2024

`// 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';
    }
}`

@djaffer
Copy link

djaffer commented Dec 2, 2024

yes it is not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants