Image-to-Text
Transformers.js
ONNX
English
multi_modality
webgpu
multimodal
text-to-image
vision-language
janus
browser-ai
edge-ai
Instructions to use Zhare-AI/janus-pro-7b-webgpu with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use Zhare-AI/janus-pro-7b-webgpu with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('image-to-text', 'Zhare-AI/janus-pro-7b-webgpu');
| // Janus Model Test Script | |
| // Test if the model can be loaded successfully | |
| import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers"; | |
| async function testJanusModel() { | |
| console.log("Testing Janus Model Loading..."); | |
| const modelPath = + str(model_dir) + ; | |
| try { | |
| console.log("Loading processor..."); | |
| const processor = await AutoProcessor.from_pretrained(modelPath); | |
| console.log("Processor loaded successfully"); | |
| console.log("Loading model..."); | |
| const model = await MultiModalityCausalLM.from_pretrained(modelPath, { | |
| device: "webgpu", | |
| dtype: "q4f16" | |
| }); | |
| console.log("Model loaded successfully"); | |
| console.log(" | |
| SUCCESS! Model initialization complete"); | |
| console.log("Model is ready for inference"); | |
| return { model, processor }; | |
| } catch (error) { | |
| console.error("Model loading failed:"); | |
| console.error(error); | |
| // Try CPU fallback | |
| console.log(" | |
| Trying CPU fallback..."); | |
| try { | |
| const processor = await AutoProcessor.from_pretrained(modelPath); | |
| const model = await MultiModalityCausalLM.from_pretrained(modelPath, { | |
| device: "cpu" | |
| }); | |
| console.log("CPU fallback successful"); | |
| return { model, processor }; | |
| } catch (cpuError) { | |
| console.error("CPU fallback also failed:"); | |
| console.error(cpuError); | |
| throw cpuError; | |
| } | |
| } | |
| } | |
| // Run the test | |
| testJanusModel() | |
| .then(() => console.log(" | |
| Test completed successfully")) | |
| .catch(error => console.error(" | |
| Test failed:", error)); | |
| export { testJanusModel }; | |