Skip to content

Unrestricted Open-source alternative to AI video platforms — Free AI image & video generation studio with 600+ models (Flux, Midjourney, Kling, Sora, Veo). No content filters. Self-hosted, MIT licensed.

feat(local-ai): add Wan2GP HTTP provider as a second local engine

Anil Matcha032ab0c693ea
diff --git a/electron/lib/wan2gpProvider.js b/electron/lib/wan2gpProvider.js
new file mode 100644
index 00000000..7d4786a5
--- /dev/null
+++ b/electron/lib/wan2gpProvider.js
@@ -0,0 +1,287 @@
+// Wan2GP HTTP provider — alternate local engine alongside sd.cpp.
+// User runs Wan2GP themselves (https://github.com/deepbeepmeep/Wan2GP) and
+// points this app at its Gradio server. We never bundle Python or weights.
+// Useful when sd.cpp can't run a model (e.g. video) or the user has a
+// dedicated CUDA box and only wants this Mac as the UI.
+
+const { ipcMain, app, BrowserWindow } = require('electron');
+const path = require('path');
+const fs = require('fs');
+const http = require('http');
+const https = require('https');
+
+const DATA_DIR = path.join(app.getPath('userData'), 'local-ai');
+const CONFIG_FILE = path.join(DATA_DIR, 'wan2gp.json');
+fs.mkdirSync(DATA_DIR, { recursive: true });
+
+// ─── Catalog ──────────────────────────────────────────────────────────────────
+// `fn` is the Gradio function name Wan2GP exposes via /gradio_api/call/<fn>.
+// If the upstream Wan2GP build names them differently, change `fn` only —
+// hit <server>/?view=api to read real names.
+const WAN2GP_CATALOG = [
+ {
+ id: 'wan2gp:flux-dev',
+ name: 'Flux.1 Dev (Wan2GP)',
+ description: 'Image — FLUX.1 dev served by Wan2GP. 1024px output.',
+ type: 'image',
+ family: 'flux',
+ provider: 'wan2gp',
+ fn: 'flux',
+ aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
+ defaultSteps: 28,
+ defaultGuidance: 3.5,
+ tags: ['image', 'flux', 'remote'],
+ },
+ {
+ id: 'wan2gp:qwen-image',
+ name: 'Qwen Image (Wan2GP)',
+ description: 'Image — Qwen-Image text-to-image served by Wan2GP.',
+ type: 'image',
+ family: 'qwen',
+ provider: 'wan2gp',
+ fn: 'qwen_image',
+ aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
+ defaultSteps: 30,
+ defaultGuidance: 4.0,
+ tags: ['image', 'qwen', 'remote'],
+ },
+ {
+ id: 'wan2gp:wan22-t2v',
+ name: 'Wan 2.2 (Text-to-Video)',
+ description: 'Video — Wan 2.2 text-to-video. Slow on consumer GPUs.',
+ type: 'video',
+ family: 'wan',
+ provider: 'wan2gp',
+ fn: 'wan22_t2v',
+ aspectRatios: ['16:9', '1:1', '9:16'],
+ defaultSteps: 25,
+ defaultGuidance: 5.0,
+ tags: ['video', 'wan', 'text-to-video'],
+ },
+ {
+ id: 'wan2gp:hunyuan-video',
+ name: 'Hunyuan Video (Wan2GP)',
+ description: 'Video — Hunyuan text-to-video via Wan2GP.',
+ type: 'video',
+ family: 'hunyuan',
+ provider: 'wan2gp',
+ fn: 'hunyuan_video',
+ aspectRatios: ['16:9', '1:1', '9:16'],
+ defaultSteps: 30,
+ defaultGuidance: 6.0,
+ tags: ['video', 'hunyuan'],
+ },
+ {
+ id: 'wan2gp:ltx-video',
+ name: 'LTX Video (Wan2GP)',
+ description: 'Video — LTX text-to-video. Fastest video option in Wan2GP.',
+ type: 'video',
+ family: 'ltx',
+ provider: 'wan2gp',
+ fn: 'ltx_video',
+ aspectRatios: ['16:9', '1:1', '9:16'],
+ defaultSteps: 20,
+ defaultGuidance: 3.0,
+ tags: ['video', 'ltx', 'fast'],
+ },
+];
+
+function getModelById(id) { return WAN2GP_CATALOG.find(m => m.id === id) || null; }
+
+// ─── Config ───────────────────────────────────────────────────────────────────
+function readConfig() {
+ if (!fs.existsSync(CONFIG_FILE)) return { url: '' };
+ try { return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf-8')); }
+ catch { return { url: '' }; }
+}
+function writeConfig(cfg) { fs.writeFileSync(CONFIG_FILE, JSON.stringify(cfg, null, 2)); }
+function normalizeUrl(url) { return (url || '').trim().replace(/\/+$/, ''); }
+
+// ─── State ────────────────────────────────────────────────────────────────────
+let activeAbort = null;
+
+// ─── HTTP helpers ─────────────────────────────────────────────────────────────
+function httpJson(urlStr, { method = 'GET', body = null, timeoutMs = 5000 } = {}) {
+ return new Promise((resolve, reject) => {
+ const u = new URL(urlStr);
+ const mod = u.protocol === 'https:' ? https : http;
+ const headers = body ? { 'Content-Type': 'application/json' } : {};
+ const req = mod.request({
+ hostname: u.hostname, port: u.port, path: u.pathname + u.search,
+ method, headers,
+ }, (res) => {
+ let buf = '';
+ res.on('data', (d) => { buf += d; });
+ res.on('end', () => resolve({ status: res.statusCode, body: buf }));
+ res.on('error', reject);
+ });
+ req.on('error', reject);
+ req.setTimeout(timeoutMs, () => req.destroy(new Error('Request timed out')));
+ if (body) req.write(body);
+ req.end();
+ });
+}
+
+async function probe(url) {
+ const base = normalizeUrl(url);
+ if (!base) return { ok: false, error: 'URL is empty' };
+ try {
+ const res = await httpJson(`${base}/config`, { timeoutMs: 5000 });
+ if (res.status !== 200) return { ok: false, error: `HTTP ${res.status} from /config — is this a Gradio server?` };
+ const cfg = JSON.parse(res.body);
+ return { ok: true, version: cfg.version || 'unknown' };
+ } catch (e) {
+ return { ok: false, error: e.message };
+ }
+}
+
+async function listModels() {
+ const { url } = readConfig();
+ const reachable = url ? (await probe(url)).ok : false;
+ return WAN2GP_CATALOG.map(m => ({ ...m, ready: reachable }));
+}
+
+// ─── Generate ─────────────────────────────────────────────────────────────────
+function arToDimensions(ar) {
+ const base = 1024;
+ const map = {
+ '1:1': [base, base],
+ '16:9': [Math.round(base * 16 / 9 / 64) * 64, base],
+ '9:16': [base, Math.round(base * 16 / 9 / 64) * 64],
+ '4:3': [Math.round(base * 4 / 3 / 64) * 64, base],
+ '3:4': [base, Math.round(base * 4 / 3 / 64) * 64],
+ };
+ return map[ar] || [base, base];
+}
+
+// Gradio v4 protocol: POST /gradio_api/call/<fn> → { event_id }
+// GET /gradio_api/call/<fn>/<event_id> → SSE stream
+async function gradioCall(base, fn, payload, onProgress, signal) {
+ const post = await fetch(`${base}/gradio_api/call/${fn}`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(payload),
+ signal,
+ });
+ if (!post.ok) throw new Error(`Wan2GP POST /call/${fn} → HTTP ${post.status}`);
+ const { event_id } = await post.json();
+ if (!event_id) throw new Error('Wan2GP did not return an event_id');
+
+ const stream = await fetch(`${base}/gradio_api/call/${fn}/${event_id}`, { signal });
+ if (!stream.ok) throw new Error(`Wan2GP stream → HTTP ${stream.status}`);
+
+ const reader = stream.body.getReader();
+ const dec = new TextDecoder();
+ let buf = '';
+
+ while (true) {
+ const { value, done } = await reader.read();
+ if (done) break;
+ buf += dec.decode(value, { stream: true });
+
+ const blocks = buf.split('\n\n');
+ buf = blocks.pop();
+ for (const block of blocks) {
+ const eMatch = block.match(/event:\s*(\S+)/);
+ const dMatch = block.match(/data:\s*(.*)$/s);
+ if (!eMatch) continue;
+ const evt = eMatch[1];
+ const dataStr = dMatch ? dMatch[1].trim() : '';
+
+ if (evt === 'generating' || evt === 'process_generating') {
+ const m = dataStr.match(/"progress":\s*([\d.]+)/);
+ if (m && onProgress) onProgress(parseFloat(m[1]));
+ } else if (evt === 'complete' || evt === 'process_completes') {
+ try {
+ const parsed = JSON.parse(dataStr);
+ return Array.isArray(parsed) ? parsed : (parsed.data || parsed);
+ } catch {
+ throw new Error(`Wan2GP returned malformed completion: ${dataStr.slice(0, 200)}`);
+ }
+ } else if (evt === 'error' || evt === 'process_error') {
+ throw new Error(`Wan2GP error: ${dataStr.slice(0, 200)}`);
+ }
+ }
+ }
+ throw new Error('Wan2GP stream ended without a completion event');
+}
+
+function resolveOutputUrl(base, output) {
+ const first = Array.isArray(output) ? output[0] : output;
+ if (!first) return null;
+ if (typeof first === 'string') {
+ return first.startsWith('http') ? first : `${base}/file=${first.replace(/^\/+/, '')}`;
+ }
+ if (first.url) return first.url.startsWith('http') ? first.url : `${base}${first.url}`;
+ if (first.path) return `${base}/file=${first.path.replace(/^\/+/, '')}`;
+ return null;
+}
+
+async function generate(params, mainWindow) {
+ const { url } = readConfig();
+ if (!url) throw new Error('Wan2GP server URL not set. Open Settings → Local Models to configure.');
+ const base = normalizeUrl(url);
+
+ const model = getModelById(params.model);
+ if (!model) throw new Error(`Unknown Wan2GP model: ${params.model}`);
+
+ const send = (data) => mainWindow?.webContents.send('local-ai:progress', data);
+ send({ status: 'starting', progress: 0 });
+
+ const [width, height] = arToDimensions(params.aspect_ratio || '1:1');
+ const seed = params.seed && params.seed !== -1 ? params.seed : Math.floor(Math.random() * 2147483647);
+ const steps = params.steps ?? model.defaultSteps;
+ const guidance = params.guidance_scale ?? model.defaultGuidance;
+
+ // Generic positional input — adjust upstream `fn` if signature differs.
+ const payload = {
+ data: [
+ params.prompt || '',
+ params.negative_prompt || '',
+ width, height, steps, guidance, seed,
+ params.image || null,
+ ],
+ };
+
+ const ac = new AbortController();
+ activeAbort = ac;
+
+ try {
+ const result = await gradioCall(base, model.fn, payload, (p) => {
+ send({ status: 'generating', progress: p });
+ }, ac.signal);
+ activeAbort = null;
+
+ const mediaUrl = resolveOutputUrl(base, result);
+ if (!mediaUrl) throw new Error(`Wan2GP returned unrecognized output: ${JSON.stringify(result).slice(0, 200)}`);
+
+ send({ status: 'done', progress: 1 });
+ return { url: mediaUrl, mediaType: model.type, seed };
+ } catch (e) {
+ activeAbort = null;
+ if (e.name === 'AbortError') throw new Error('Generation cancelled');
+ throw e;
+ }
+}
+
+function cancelGeneration() {
+ if (activeAbort) {
+ activeAbort.abort();
+ activeAbort = null;
+ }
+ return { ok: true };
+}
+
+// ─── IPC ──────────────────────────────────────────────────────────────────────
+function getMainWindow() { return BrowserWindow.getAllWindows()[0] || null; }
+
+function register() {
+ ipcMain.handle('wan2gp:get-config', () => readConfig());
+ ipcMain.handle('wan2gp:set-url', (_, url) => { writeConfig({ url: normalizeUrl(url) }); return { ok: true }; });
+ ipcMain.handle('wan2gp:probe', (_, url) => probe(url));
+ ipcMain.handle('wan2gp:list-models', () => listModels());
+ ipcMain.handle('wan2gp:generate', (_, params) => generate(params, getMainWindow()));
+ ipcMain.handle('wan2gp:cancel-generation', () => cancelGeneration());
+}
+
+module.exports = { register, WAN2GP_CATALOG };
diff --git a/electron/main.js b/electron/main.js
index 2bb2eb6d..669f20ee 100644
--- a/electron/main.js
+++ b/electron/main.js
@@ -1,6 +1,7 @@
const { app, BrowserWindow, shell } = require('electron');
const path = require('path');
const { register: registerLocalInference } = require('./lib/localInference');
+const { register: registerWan2gp } = require('./lib/wan2gpProvider');
// Ubuntu 24.04+ sets kernel.apparmor_restrict_unprivileged_userns=1 which
// blocks Chromium's user namespace sandbox. The .deb package ships an AppArmor
@@ -60,6 +61,7 @@ function createWindow() {
app.whenReady().then(() => {
createWindow();
registerLocalInference();
+ registerWan2gp();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
diff --git a/electron/preload.js b/electron/preload.js
index 8767ef30..cc501e4e 100644
--- a/electron/preload.js
+++ b/electron/preload.js
@@ -3,22 +3,30 @@ const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('localAI', {
isElectron: true,
- // Binary management
+ // ── sd.cpp engine ──────────────────────────────────────────────────────
getBinaryStatus: () => ipcRenderer.invoke('local-ai:binary-status'),
downloadBinary: () => ipcRenderer.invoke('local-ai:download-binary'),
- // Model management
listModels: () => ipcRenderer.invoke('local-ai:list-models'),
downloadModel: (modelId) => ipcRenderer.invoke('local-ai:download-model', modelId),
downloadAuxiliary: (auxKey) => ipcRenderer.invoke('local-ai:download-auxiliary', auxKey),
deleteModel: (modelId) => ipcRenderer.invoke('local-ai:delete-model', modelId),
cancelDownload: (modelId) => ipcRenderer.invoke('local-ai:cancel-download', modelId),
- // Generation
generate: (params) => ipcRenderer.invoke('local-ai:generate', params),
cancelGeneration: () => ipcRenderer.invoke('local-ai:cancel-generation'),
- // Progress events — returns an unsubscribe function
+ // ── Wan2GP engine (remote Gradio server) ───────────────────────────────
+ wan2gp: {
+ getConfig: () => ipcRenderer.invoke('wan2gp:get-config'),
+ setUrl: (url) => ipcRenderer.invoke('wan2gp:set-url', url),
+ probe: (url) => ipcRenderer.invoke('wan2gp:probe', url),
+ listModels: () => ipcRenderer.invoke('wan2gp:list-models'),
+ generate: (params) => ipcRenderer.invoke('wan2gp:generate', params),
+ cancelGeneration: () => ipcRenderer.invoke('wan2gp:cancel-generation'),
+ },
+
+ // Progress events — both engines emit on local-ai:progress
onProgress: (callback) => {
const listener = (_, data) => callback(data);
ipcRenderer.on('local-ai:progress', listener);
@@ -28,5 +36,5 @@ contextBridge.exposeInMainWorld('localAI', {
const listener = (_, data) => callback(data);
ipcRenderer.on('local-ai:download-progress', listener);
return () => ipcRenderer.removeListener('local-ai:download-progress', listener);
- }
+ },
});
diff --git a/src/components/ImageStudio.js b/src/components/ImageStudio.js
index a8f49d74..18a1f4c2 100644
--- a/src/components/ImageStudio.js
+++ b/src/components/ImageStudio.js
@@ -35,9 +35,12 @@ export function ImageStudio() {
let uploadedImageUrls = []; // array of uploaded image URLs (multi-image support)
let imageMode = false; // false = t2i models, true = i2i models
- // Local inference state
+ // Local inference state — only image-capable models surface here.
+ // sd.cpp uses type='sd1'|'sdxl'|'z-image'; Wan2GP image models use type='image'.
+ // Wan2GP video models (type='video') are hidden from ImageStudio.
+ const LOCAL_IMAGE_MODELS = LOCAL_MODEL_CATALOG.filter(m => m.type !== 'video');
let useLocalModel = false;
- let selectedLocalModel = LOCAL_MODEL_CATALOG[0]?.id || null;
+ let selectedLocalModel = LOCAL_IMAGE_MODELS[0]?.id || null;
let localGenProgress = 0; // 0–1
// Advanced parameters state
@@ -728,8 +731,8 @@ export function ImageStudio() {
list.innerHTML = '';
if (useLocalModel) {
- // ── Local model list ──────────────────────────────────────
- const filtered = LOCAL_MODEL_CATALOG.filter(m =>
+ // ── Local model list (Wan2GP image-capable models only) ───
+ const filtered = LOCAL_IMAGE_MODELS.filter(m =>
m.name.toLowerCase().includes(filter.toLowerCase()) ||
m.id.toLowerCase().includes(filter.toLowerCase())
);
@@ -748,7 +751,7 @@ export function ImageStudio() {
<span class="text-xs font-bold text-white tracking-tight">${m.name}</span>
${m.featured ? '<span class="text-[9px] font-black px-1 py-0.5 rounded bg-primary/20 text-primary">FEATURED</span>' : ''}
</div>
- <span class="text-[10px] text-muted">${m.sizeGB} GB · ${m.type.toUpperCase()}</span>
+ <span class="text-[10px] text-muted">${m.type.toUpperCase()} · ${m.family}</span>
</div>
</div>
${selectedLocalModel === m.id ? '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#d9ff00" stroke-width="4"><polyline points="20 6 9 17 4 12"/></svg>' : ''}
@@ -1177,11 +1180,11 @@ export function ImageStudio() {
progressWrap.classList.remove('hidden');
progressWrap.classList.add('flex');
- const unsub = localAI.onProgress(({ step, totalSteps, progress, status }) => {
- const pct = Math.round((progress || (step / totalSteps)) * 100);
+ const unsub = localAI.onProgress(({ progress, status }) => {
+ const pct = Math.round((progress ?? 0) * 100);
if (progressFill) progressFill.style.width = `${pct}%`;
- if (progressPct) progressPct.textContent = `${pct}%`;
- generateBtn.innerHTML = `<span class="animate-spin inline-block mr-2 text-black">◌</span> ${pct}%`;
+ if (progressPct) progressPct.textContent = status === 'starting' ? 'Starting...' : `${pct}%`;
+ generateBtn.innerHTML = `<span class="animate-spin inline-block mr-2 text-black">◌</span> ${status === 'starting' ? '...' : pct + '%'}`;
});
let hadError = false;
@@ -1199,20 +1202,20 @@ export function ImageStudio() {
progressWrap.classList.replace('flex', 'hidden');
progressWrap.classList.add('hidden');
- if (res?.url) {
- addToHistory({
- id: Date.now().toString(),
- url: res.url,
- prompt,
- model: `local:${selectedLocalModel}`,
- aspect_ratio: selectedAr,
- seed: res.seed,
- timestamp: new Date().toISOString()
- });
- showImageInCanvas(res.url);
- } else {
- throw new Error('No image returned from local generation');
+ if (!res?.url) throw new Error('No output returned from local generation');
+ if (res.mediaType === 'video') {
+ throw new Error('This model produces video — use the Video studio instead.');
}
+ addToHistory({
+ id: Date.now().toString(),
+ url: res.url,
+ prompt,
+ model: `local:${selectedLocalModel}`,
+ aspect_ratio: selectedAr,
+ seed: res.seed,
+ timestamp: new Date().toISOString()
+ });
+ showImageInCanvas(res.url);
} catch (e) {
hadError = true;
unsub();
diff --git a/src/components/LocalModelManager.js b/src/components/LocalModelManager.js
index 83df068a..0fd0ba9e 100644
--- a/src/components/LocalModelManager.js
+++ b/src/components/LocalModelManager.js
@@ -152,8 +152,100 @@ function AuxRow(label, auxKey, initStatus, onStateChange) {
return row;
}
+// ─── Wan2GP Server Config ────────────────────────────────────────────────────
+function Wan2gpConfigBar(onChange) {
+ const wrap = document.createElement('div');
+ wrap.className = 'flex flex-col gap-3 p-3 rounded-xl bg-white/3 border border-white/5';
+ wrap.innerHTML = `
+ <div class="flex flex-col gap-0.5">
+ <span class="text-xs font-bold text-white">Wan2GP server (optional)</span>
+ <span class="text-[11px] text-muted leading-relaxed">
+ Run <a href="https://github.com/deepbeepmeep/Wan2GP" target="_blank" class="text-primary hover:underline">Wan2GP</a>
+ on a CUDA box (<code class="text-primary/80">python wgp.py --listen --server-name 0.0.0.0</code>) to unlock video models from this UI.
+ </span>
+ </div>
+ <div class="flex items-center gap-2">
+ <input id="wan2gp-url" type="text" placeholder="http://127.0.0.1:7860"
+ class="flex-1 bg-white/5 border border-white/5 focus:border-primary/40 rounded-lg px-3 py-1.5 text-xs text-white placeholder-white/30 focus:outline-none"/>
+ <button id="wan2gp-test" class="px-3 py-1.5 rounded-lg text-xs font-bold bg-primary/20 text-primary border border-primary/30 hover:bg-primary/30 transition-all">Test</button>
+ <button id="wan2gp-save" class="px-3 py-1.5 rounded-lg text-xs font-bold bg-primary text-black hover:shadow-glow transition-all">Save</button>
+ </div>
+ <div id="wan2gp-status" class="text-[11px] text-muted">Not configured</div>
+ `;
+
+ const input = wrap.querySelector('#wan2gp-url');
+ const testBtn = wrap.querySelector('#wan2gp-test');
+ const saveBtn = wrap.querySelector('#wan2gp-save');
+ const statusEl = wrap.querySelector('#wan2gp-status');
+ const setStatus = (text, kind = 'muted') => {
+ const colorMap = { muted: 'text-muted', ok: 'text-green-400', warn: 'text-yellow-400', err: 'text-red-400' };
+ statusEl.className = `text-[11px] ${colorMap[kind] || colorMap.muted}`;
+ statusEl.textContent = text;
+ };
+
+ (async () => {
+ const cfg = await localAI.getWan2gpConfig();
+ if (cfg.url) {
+ input.value = cfg.url;
+ const r = await localAI.probeWan2gp(cfg.url);
+ setStatus(r.ok ? `Connected · Gradio ${r.version}` : `Saved URL not reachable: ${r.error}`, r.ok ? 'ok' : 'warn');
+ } else {
+ setStatus('Not configured (Wan2GP models will appear offline)', 'muted');
+ }
+ })();
+
+ testBtn.onclick = async () => {
+ const url = input.value.trim();
+ if (!url) { setStatus('Enter a URL first', 'warn'); return; }
+ setStatus('Probing...', 'muted');
+ testBtn.disabled = true;
+ try {
+ const r = await localAI.probeWan2gp(url);
+ setStatus(r.ok ? `Reachable · Gradio ${r.version}` : `Unreachable: ${r.error}`, r.ok ? 'ok' : 'err');
+ } finally { testBtn.disabled = false; }
+ };
+
+ saveBtn.onclick = async () => {
+ const url = input.value.trim();
+ saveBtn.disabled = true;
+ try {
+ await localAI.setWan2gpUrl(url);
+ const r = url ? await localAI.probeWan2gp(url) : { ok: false, error: 'cleared' };
+ setStatus(r.ok ? `Saved · Connected to Gradio ${r.version}` : (url ? `Saved, not reachable: ${r.error}` : 'Cleared'), r.ok ? 'ok' : 'warn');
+ onChange?.();
+ } finally { saveBtn.disabled = false; }
+ };
+
+ return wrap;
+}
+
// ─── Model Card ───────────────────────────────────────────────────────────────
+function Wan2gpModelCard(model) {
+ const card = document.createElement('div');
+ card.className = 'flex items-start justify-between gap-3 p-4 rounded-xl border border-white/5 bg-white/3';
+ const ready = !!model.ready;
+ card.innerHTML = `
+ <div class="flex flex-col gap-1 min-w-0">
+ <div class="flex items-center gap-2 flex-wrap">
+ <span class="text-sm font-bold text-white truncate">${model.name}</span>
+ ${ready ? `<span class="text-green-400">${CheckIcon}</span>` : ''}
+ </div>
+ <p class="text-[11px] text-muted leading-relaxed">${model.description}</p>
+ <div class="flex items-center gap-1.5 flex-wrap mt-1">
+ <span class="px-1.5 py-0.5 rounded-md text-[10px] font-bold ${model.type === 'video' ? 'bg-purple-500/15 text-purple-300' : 'bg-primary/10 text-primary'}">${model.type.toUpperCase()}</span>
+ <span class="px-1.5 py-0.5 rounded-md text-[10px] font-bold bg-white/5 text-muted">via Wan2GP</span>
+ ${(model.tags || []).filter(t => !['featured', 'remote'].includes(t)).map(t => `<span class="px-1.5 py-0.5 rounded-md text-[10px] font-bold bg-white/5 text-muted">${t}</span>`).join('')}
+ </div>
+ </div>
+ <div class="shrink-0">
+ <span class="text-[10px] font-bold ${ready ? 'text-green-400' : 'text-yellow-400'}">${ready ? 'Available' : 'Server offline'}</span>
+ </div>
+ `;
+ return card;
+}
+
function ModelCard(model, onStateChange) {
+ if (model.provider === 'wan2gp') return Wan2gpModelCard(model);
const card = document.createElement('div');
card.className = 'flex flex-col gap-3 p-4 rounded-xl border border-white/5 bg-white/3 hover:border-white/10 transition-all';
@@ -267,6 +359,9 @@ export function LocalModelManager() {
let binaryReady = false;
const binaryBar = BinaryStatusBar((ready) => { binaryReady = ready; });
engineSection.appendChild(binaryBar);
+
+ const wan2gpBar = Wan2gpConfigBar(() => renderModels());
+ engineSection.appendChild(wan2gpBar);
root.appendChild(engineSection);
// ── Section: models
diff --git a/src/lib/localInferenceClient.js b/src/lib/localInferenceClient.js
index fccd7867..8dc224e7 100644
--- a/src/lib/localInferenceClient.js
+++ b/src/lib/localInferenceClient.js
@@ -1,67 +1,90 @@
// Frontend client for local inference — wraps window.localAI (Electron IPC).
-// Falls back gracefully when running in browser/dev mode.
+// Two providers live behind the same surface:
+// - sd.cpp: bundled engine, downloads weights to disk, runs locally
+// - wan2gp: user-run Gradio server, generation is remote HTTP
+// Provider is read off the model entry's `provider` field.
+
+import { getLocalModelById } from './localModels.js';
export const isLocalAIAvailable = () => typeof window !== 'undefined' && !!window.localAI?.isElectron;
class LocalInferenceClient {
+ // ── sd.cpp APIs ───────────────────────────────────────────────────────
async getBinaryStatus() {
if (!isLocalAIAvailable()) return { exists: false };
return window.localAI.getBinaryStatus();
}
-
async downloadBinary() {
if (!isLocalAIAvailable()) throw new Error('Local AI only available in the desktop app.');
return window.localAI.downloadBinary();
}
-
- async listModels() {
- if (!isLocalAIAvailable()) return [];
- return window.localAI.listModels();
- }
-
async downloadModel(modelId) {
if (!isLocalAIAvailable()) throw new Error('Local AI only available in the desktop app.');
return window.localAI.downloadModel(modelId);
}
-
async downloadAuxiliary(auxKey) {
if (!isLocalAIAvailable()) throw new Error('Local AI only available in the desktop app.');
return window.localAI.downloadAuxiliary(auxKey);
}
-
async deleteModel(modelId) {
if (!isLocalAIAvailable()) throw new Error('Local AI only available in the desktop app.');
return window.localAI.deleteModel(modelId);
}
- /**
- * Generate an image locally using sd.cpp.
- * Returns { url: 'data:image/png;base64,...', seed }
- */
+ // ── Wan2GP APIs ───────────────────────────────────────────────────────
+ async getWan2gpConfig() {
+ if (!isLocalAIAvailable()) return { url: '' };
+ return window.localAI.wan2gp.getConfig();
+ }
+ async setWan2gpUrl(url) {
+ if (!isLocalAIAvailable()) throw new Error('Local AI only available in the desktop app.');
+ return window.localAI.wan2gp.setUrl(url);
+ }
+ async probeWan2gp(url) {
+ if (!isLocalAIAvailable()) return { ok: false, error: 'Not in desktop app' };
+ return window.localAI.wan2gp.probe(url);
+ }
+
+ // ── Unified model list (both providers merged) ────────────────────────
+ async listModels() {
+ if (!isLocalAIAvailable()) return [];
+ const [sdcpp, wan2gp] = await Promise.all([
+ window.localAI.listModels(),
+ window.localAI.wan2gp.listModels().catch(() => []),
+ ]);
+ return [
+ ...sdcpp.map(m => ({ ...m, provider: m.provider || 'sdcpp' })),
+ ...wan2gp,
+ ];
+ }
+
+ // ── Provider-aware generate ───────────────────────────────────────────
async generate(params) {
if (!isLocalAIAvailable()) throw new Error('Local AI only available in the desktop app.');
+ const model = getLocalModelById(params.model);
+ if (model?.provider === 'wan2gp') {
+ return window.localAI.wan2gp.generate(params);
+ }
return window.localAI.generate(params);
}
cancelGeneration() {
- if (isLocalAIAvailable()) window.localAI.cancelGeneration();
+ if (!isLocalAIAvailable()) return;
+ // Ask both — only the running one reacts.
+ window.localAI.cancelGeneration();
+ window.localAI.wan2gp.cancelGeneration();
}
/**
* Subscribe to generation progress events.
- * @param {function} callback - ({ step, totalSteps, progress, status }) => void
- * @returns unsubscribe function
+ * sd.cpp emits { step, totalSteps, progress, status }.
+ * Wan2GP emits { progress, status }.
*/
onProgress(callback) {
if (!isLocalAIAvailable()) return () => {};
return window.localAI.onProgress(callback);
}
- /**
- * Subscribe to download progress events.
- * @param {function} callback - ({ id, phase, progress }) => void
- * @returns unsubscribe function
- */
onDownloadProgress(callback) {
if (!isLocalAIAvailable()) return () => {};
return window.localAI.onDownloadProgress(callback);
diff --git a/src/lib/localModels.js b/src/lib/localModels.js
index 4e6b87fd..fae4d6de 100644
--- a/src/lib/localModels.js
+++ b/src/lib/localModels.js
@@ -1,11 +1,16 @@
-// Frontend-side local model catalog (mirrors electron/lib/modelCatalog.js)
+// Frontend-side local model catalog.
+// Two providers:
+// - sdcpp: bundled engine, weights live on disk
+// - wan2gp: user-run remote Gradio server
+// Mirrors electron/lib/modelCatalog.js (sd.cpp) and electron/lib/wan2gpProvider.js (wan2gp).
export const LOCAL_MODEL_CATALOG = [
- // ── Z-Image (Tongyi-MAI) ────────────────────────────────────────────────
+ // ── sd.cpp: Z-Image (Tongyi-MAI) ────────────────────────────────────────
{
id: 'z-image-turbo',
name: 'Z-Image Turbo',
description: 'WaveSpeed\'s featured local model — 6B params, ultra-fast 8-step generation. No API key needed.',
type: 'z-image',
+ provider: 'sdcpp',
filename: 'z_image_turbo-Q4_K.gguf',
sizeGB: 3.4,
aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
@@ -19,6 +24,7 @@ export const LOCAL_MODEL_CATALOG = [
name: 'Z-Image Base',
description: 'Full-quality 6B parameter model from Tongyi-MAI — higher detail, 50-step generation.',
type: 'z-image',
+ provider: 'sdcpp',
filename: 'Z-Image-Q4_K_M.gguf',
sizeGB: 3.5,
aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
@@ -27,12 +33,13 @@ export const LOCAL_MODEL_CATALOG = [
tags: ['high-quality', 'local', 'detailed'],
featured: true,
},
- // ── Classic SD 1.5 ──────────────────────────────────────────────────────
+ // ── sd.cpp: SD 1.5 (small, M2-friendly) ─────────────────────────────────
{
id: 'dreamshaper-8',
name: 'Dreamshaper 8',
description: 'Versatile SD 1.5 model — great for portraits, landscapes, and artistic styles.',
type: 'sd1',
+ provider: 'sdcpp',
filename: 'DreamShaper_8_pruned.safetensors',
sizeGB: 2.1,
aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
@@ -45,6 +52,7 @@ export const LOCAL_MODEL_CATALOG = [
name: 'Realistic Vision v5.1',
description: 'Highly photorealistic people and scenes, based on SD 1.5.',
type: 'sd1',
+ provider: 'sdcpp',
filename: 'realisticVisionV51_v51VAE.safetensors',
sizeGB: 2.1,
aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
@@ -57,6 +65,7 @@ export const LOCAL_MODEL_CATALOG = [
name: 'Anything v5',
description: 'High quality anime and illustration style image generation.',
type: 'sd1',
+ provider: 'sdcpp',
filename: 'anything-v5-PrtRE.safetensors',
sizeGB: 2.1,
aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
@@ -64,12 +73,13 @@ export const LOCAL_MODEL_CATALOG = [
defaultGuidance: 7,
tags: ['anime', 'illustration', 'artistic'],
},
- // ── SDXL ────────────────────────────────────────────────────────────────
+ // ── sd.cpp: SDXL ────────────────────────────────────────────────────────
{
id: 'stable-diffusion-xl-base',
name: 'SDXL Base 1.0',
description: 'Official Stable Diffusion XL base model — higher resolution, excellent quality.',
type: 'sdxl',
+ provider: 'sdcpp',
filename: 'sd_xl_base_1.0.safetensors',
sizeGB: 6.9,
aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
@@ -77,6 +87,69 @@ export const LOCAL_MODEL_CATALOG = [
defaultGuidance: 7.5,
tags: ['sdxl', 'high-quality', 'versatile'],
},
+
+ // ── Wan2GP: image models ────────────────────────────────────────────────
+ {
+ id: 'wan2gp:flux-dev',
+ name: 'Flux.1 Dev (Wan2GP)',
+ description: 'Image — FLUX.1 dev served by Wan2GP. Requires running Wan2GP server.',
+ type: 'image',
+ family: 'flux',
+ provider: 'wan2gp',
+ aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
+ defaultSteps: 28,
+ defaultGuidance: 3.5,
+ tags: ['image', 'flux', 'remote'],
+ },
+ {
+ id: 'wan2gp:qwen-image',
+ name: 'Qwen Image (Wan2GP)',
+ description: 'Image — Qwen-Image text-to-image served by Wan2GP.',
+ type: 'image',
+ family: 'qwen',
+ provider: 'wan2gp',
+ aspectRatios: ['1:1', '4:3', '3:4', '16:9', '9:16'],
+ defaultSteps: 30,
+ defaultGuidance: 4.0,
+ tags: ['image', 'qwen', 'remote'],
+ },
+ // ── Wan2GP: video models ────────────────────────────────────────────────
+ {
+ id: 'wan2gp:wan22-t2v',
+ name: 'Wan 2.2 (Text-to-Video)',
+ description: 'Video — Wan 2.2 text-to-video. Slow on consumer GPUs.',
+ type: 'video',
+ family: 'wan',
+ provider: 'wan2gp',
+ aspectRatios: ['16:9', '1:1', '9:16'],
+ defaultSteps: 25,
+ defaultGuidance: 5.0,
+ tags: ['video', 'wan', 'text-to-video'],
+ },
+ {
+ id: 'wan2gp:hunyuan-video',
+ name: 'Hunyuan Video (Wan2GP)',
+ description: 'Video — Hunyuan text-to-video via Wan2GP.',
+ type: 'video',
+ family: 'hunyuan',
+ provider: 'wan2gp',
+ aspectRatios: ['16:9', '1:1', '9:16'],
+ defaultSteps: 30,
+ defaultGuidance: 6.0,
+ tags: ['video', 'hunyuan'],
+ },
+ {
+ id: 'wan2gp:ltx-video',
+ name: 'LTX Video (Wan2GP)',
+ description: 'Video — LTX text-to-video. Fastest video option in Wan2GP.',
+ type: 'video',
+ family: 'ltx',
+ provider: 'wan2gp',
+ aspectRatios: ['16:9', '1:1', '9:16'],
+ defaultSteps: 20,
+ defaultGuidance: 3.0,
+ tags: ['video', 'ltx', 'fast'],
+ },
];
export function getLocalModelById(id) {