Running Open-source Models projects locally
Use this page to run an extracted Open-source Models project on your computer. The module has two kinds of project. One runs an object-detection model inside your browser with Transformers.js and needs one setting added before it loads. The other is a small Express server that passes your question to a model running in Ollama, and its package.json needs a repair. Neither needs an API key.
What you need first
Install a supported LTS version of Node.js. Node 24 is recommended and includes npm. If Node and npm are new to you, Running the code locally walks through installing and checking both.
Check that both commands work. Your version numbers may be different:
$ node --version
v24.18.0
$ npm --version
11.18.0The browser project also needs an internet connection the first time it loads, because the page downloads about 20 MB of library and model files.
The Ollama project also needs Ollama and its mistral model, a download of about 4.4 GB. You start that download in the Ollama section below.
node --version and npm --version both print a version. You don't need an API key for either project. If index.js starts with import ollama, install the Ollama app too.
Identify the project you extracted
Open a terminal in the extracted folder. It is the one containing package.json and index.js:
$ cd path-to-your-extracted-projectOpen index.js and read its first line. The browser project, AI Models In The Browser With Transformers.js, starts with:
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.8.0'The Ollama project, Download and Run AI Models on Your Computer with Ollama, starts with:
import ollama from "ollama";The browser project also has index.html and a road.jpeg photo; the Ollama project has neither. Follow only the section for the project you have.
index.js and look at the first line. @xenova/transformers means the browser project; ollama means the Ollama project. Then skip to that project's section. The two setups do not mix.
Run the Transformers.js project
Install the packages:
$ npm installnpm finishes by reporting how many packages it added.
Before you start it, change one line in index.js. When the page loads, Transformers.js first looks for the model files on the same server as the page, under /models/. Vite answers any address it does not know with the page itself, so the library receives HTML where it expected the model's settings, and the page stays on Loading model... for good. One setting tells Transformers.js to skip that local check and download the model from Hugging Face straight away.
Change the first line from:
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.8.0'to these two lines:
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.8.0'
env.allowLocalModels = falseStart the development server:
$ npm startVite may first print a warning that begins (!) Your Vite config uses features. It does not stop the app. Below it, Vite prints the address to open:
VITE v8.3.4 ready in 99 ms
➜ Local: http://localhost:5173/Open the exact Local address. The page shows Loading model... above a greyed-out Detect Objects button while the library and the model download. When the status changes to Ready, select Detect Objects. After a few seconds (up to about twenty on a slower machine) the status reads Done! and labelled boxes appear on the photo, such as bus: 99%, car: 97% and several traffic lights. Later loads are faster because the browser keeps the downloaded files.
If the status stays on Loading model... or never appears, open your browser's developer tools (F12, or Cmd+Option+J in Chrome on a Mac) and read the Console tab; the troubleshooting below matches each message. A red 404 for favicon.ico is harmless.
Stop the project with Ctrl+C.
npm install, add env and the env.allowLocalModels = false line at the top of index.js, then run npm start and open the Local address. Wait for Ready, then select Detect Objects. Boxes with labels on the photo mean the model works.
Repair and run the Ollama project
Install Ollama and open it. On macOS and Windows the app starts Ollama's local service; on Linux the installer sets it up. If ollama commands say they cannot connect, run ollama serve in a separate terminal and leave it running.
Download the model the lesson code asks for. It is about 4.4 GB, so you can make the edits below in another terminal while it downloads:
$ ollama pull mistral
$ ollama lsThe second command should list mistral:latest.
Now the project itself. Its package.json was generated for a Vite web page: npm start runs Vite and the only package listed is Vite. But index.js is a Node server that imports express and ollama. As downloaded, npm start starts Vite, and the address it prints shows HTTP ERROR 404, because there is no page to serve.
Make two edits in package.json: add "type": "module" and change the start script to node index.js. The top of the file then reads:
{
"name": "Scrim-s06c53f",
"description": "https://scrimba.com/ai-engineer-path-c02v/~07uj",
"type": "module",
"scripts": {
"start": "node index.js",
"dev": "vite",Leave the rest of the file as it is. "type": "module" tells Node that index.js uses import; without it, Node still runs the file but prints a MODULE_TYPELESS_PACKAGE_JSON warning first.
Install the two packages index.js imports, then start the server:
$ npm install express ollama
$ npm startThe server prints:
Server is running on port 3000Open http://localhost:3000/. The page should say:
Ask something via the `?question=` parameterAsk only after ollama pull has finished. Then ask the model a question:
http://localhost:3000/?question=Why%20is%20the%20sky%20blue%3FThe answer appears as plain text once Mistral has finished writing it. The first answer is the slowest, because Ollama loads the model into memory first; the page shows nothing until then.
Stop the server with Ctrl+C. Ollama keeps running in the background until you quit the app or stop ollama serve.
ollama pull mistral and keep Ollama open. In package.json, add "type": "module" and change the start script to node index.js. Then run npm install express ollama and npm start, and open the question address. A slow first answer is normal.
Troubleshooting
The Transformers.js page stays on Loading model... and the console says Unexpected token '<', "<!DOCTYPE "... is not valid JSON: The env.allowLocalModels = false line is missing, or env is not in the import. Add both as shown above and reload the page.
The page shows only a greyed-out Detect Objects button with no status above it, and the console names cdn.jsdelivr.net: The library could not download. A content blocker or a restricted network is usually the cause; allow cdn.jsdelivr.net or try another network.
The page stays on Loading model... and the console says Failed to fetch for huggingface.co: The model could not download. Allow huggingface.co in your content blocker or network, then reload.
In the Ollama project, npm start prints VITE and its address shows HTTP ERROR 404: The start script still runs Vite. Change it to node index.js.
Node says Cannot find package 'ollama' or Cannot find package 'express': Run npm install express ollama in the folder containing package.json.
The question address shows TypeError: fetch failed, and the terminal shows ECONNREFUSED 127.0.0.1:11434: Express is running but Ollama is not. Open the Ollama app or run ollama serve, then ask again.
The question address shows an error saying the model mistral is not found: Ollama is running without the model. Run ollama pull mistral and wait for it to finish.
npm start prints Server is running on port 3000 and then returns to the prompt: Another program already uses port 3000. Stop it, or change the port constant in index.js and open the matching address.
favicon.ico. For the Ollama project, read what the question address shows and what the terminal printed. Then match it to a bold heading above. 
