跳到正文
DEV Community· Smart Online Tools·· 3 天前AI 評分58

Smart Online Tools 如何打造 80+ 款免費瀏覽器工具,讓 AI 功能不會上傳用戶檔案

How I built 80+ free browser tools, including AI that never uploads your files

AI 導讀

Smart Online Tools 作者打造 80+ 款免費瀏覽器工具,讓 PDF、圖像及多項 AI 處理都在訪客裝置上完成,檔案不會上傳至伺服器。網站以 Next.js 靜態匯出,使用 Transformers.js、Tesseract.js 和 MediaPipe Tasks Vision,並透過 Web Worker 執行模型,按需下載及快取。

正文

Cover image for How I built 80+ free browser tools, including AI that never uploads your files

Smart Online Tools

I wanted a set of everyday tools — merge a PDF, compress an image, read text from a screenshot — that I could use without uploading my files to someone else's server. So I built Smart Online Tools: 80+ free tools where all the processing happens in the browser.

The PDF and image tools were the easy part. The interesting part was the AI tools: OCR, speech-to-text, translation, background removal, face blurring and alt-text writing, all running on the visitor's device. Here's how that works and what I learned.

The stack

  • Next.js (App Router) as a static export. No backend at all. The whole site is HTML, JS and WebAssembly served from ordinary shared hosting.
  • Transformers.js to run ONNX models in the browser, using WebAssembly, or WebGPU where the browser supports it.
  • Tesseract.js for OCR.
  • MediaPipe Tasks Vision for face detection.
  • Web Workers, so the page never freezes while a model is working.

Which model does what

Tool Model First download
Image to text (OCR) Tesseract 2–15 MB per language
Speech to text Whisper base ≈ 80 MB
Translator OPUS-MT (Helsinki-NLP) ≈ 80–110 MB per direction
Background remover MODNet ≈ 26 MB
Blur faces MediaPipe BlazeFace < 1 MB
Alt-text generator Florence-2 base ≈ 250–450 MB

Every model has a permissive licence (MIT, Apache-2.0 or CC BY 4.0). I deliberately skipped a few good models because of their licences. For example, one popular text-to-speech model depends on a GPL phonemizer. For text to speech I use the browser's built-in device voices instead.

One worker, loaded on demand

Each model downloads only when someone actually clicks the tool. A single worker keeps loaded models in a cache, so the second run is instant:

import { env, pipeline } from "@huggingface/transformers";

env.allowLocalModels = false;
env.useBrowserCache = true; // the model is downloaded once, then reused

const cache = new Map<string, Promise<any>>();

function loadTranslator(pair: string) {
  const key = `translate:${pair}`;
  if (!cache.has(key)) {
    const p = pipeline("translation", `Xenova/opus-mt-${pair}`, { dtype: "q8" })
      .catch(() => pipeline("translation", `Xenova/opus-mt-${pair}`, { dtype: "fp32" }));
    p.catch(() => cache.delete(key)); // allow a retry after a network error
    cache.set(key, p);
  }
  return cache.get(key)!;
}

I try a quantized version first (smaller and faster), and fall back to full precision if a model doesn't ship one.

Translating 13 languages with small models

OPUS-MT models translate one direction each, for example en-de or de-en. Not every pair has a direct model, so the translator routes through English when it needs to:

const DIRECT = new Set(["de-es", "es-fr", "fr-de" /* … */]);

const route = (from: string, to: string) =>
  from === "en" || to === "en" || DIRECT.has(`${from}-${to}`)
    ? [`${from}-${to}`]
    : [`${from}-en`, `en-${to}`];

Long text is split into sentence groups of about 400 characters, so each call stays inside the model's limits and the progress bar actually moves.

Lessons learned

  1. Tell people about the download. A 100 MB model with no warning feels broken. Each tool says up front how big the first download is and that the browser will cache it.
  2. Workers are not optional. Running a model on the main thread freezes scrolling and buttons. Moving everything into a worker fixed that.
  3. Small models need honest expectations. Browser-sized models are good at focused jobs but less accurate than big cloud services. The UI says so, and the result can always be edited.
  4. Check licences before you fall in love with a model. It saved me from shipping something I'd have had to remove later.
  5. Static hosting is enough. No GPU servers and no API bills. The heavy lifting happens on the visitor's own hardware, which is also what keeps their files private.

Try it

All the AI tools are at smartonline.tools/ai-tools. They're free, need no account, and your files stay on your device.

I'd love feedback, especially on speed on your hardware, accuracy, and which tool you'd want next.

來源:DEV Community · dev.to