Add LaMa magic eraser, remote provider abstraction, and AI tool infrastructure
Backend: - requirements.txt: add simple-lama-inpainting, rembg[gpu]; upgrade opencv to 4.10+ - app/config.py: add InvokeAI (url, model) and ComfyUI (url, model) settings; OPENAI_MODEL - app/services/local_inpaint.py: LaMa, OpenCV, rembg wrappers (auto GPU/CPU) - app/services/remote_provider.py: abstract RemoteAIProvider + OpenAI, InvokeAI, ComfyUI drivers - app/routers/ai_tools.py: new /api/* endpoints — /erase, /inpaint/lama, /inpaint/fast, /background/remove, /inpaint/remote, /generate/txt2img, /generate/img2img, /generate/outpaint, GET /config (capability flags) - app/main.py: register ai_tools router Frontend: - services/api.js: add erase(), textToImage(), imageToImage(), remoteInpaint(), getConfig() - api/capabilities.js: lazy-fetch /api/config singleton; hasRemote() helper - tools/ai_lama_erase.js: brush-paint mask → LaMa erase → apply to layer - tools/ai_smart_inpaint.js: brush mask + dialog (Fast/Quality mode + prompt) → inpaint - core/components/provider-badge.js: shows active provider + health in toolbar - config.js: register ai_lama_erase and ai_smart_inpaint tools - main.js: mount provider badge on load - .env.example: document InvokeAI, ComfyUI, OpenAI provider settings https://claude.ai/code/session_01B58MaJCU1R6KwBDJCp8AfN
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Backend capabilities singleton.
|
||||
* Fetched once on load from GET /api/config.
|
||||
* Tools use this to decide whether to show, grey out, or show tooltips.
|
||||
*
|
||||
* Shape:
|
||||
* {
|
||||
* local: { lama, rembg, opencv, gpu_detected },
|
||||
* remote: { provider, capabilities: string[], healthy }
|
||||
* }
|
||||
*/
|
||||
|
||||
import apiService from '../services/api.js';
|
||||
|
||||
const DEFAULT_CAPS = {
|
||||
local: { lama: false, rembg: false, opencv: true, gpu_detected: false },
|
||||
remote: { provider: null, capabilities: [], healthy: false },
|
||||
};
|
||||
|
||||
let _caps = null;
|
||||
let _fetchPromise = null;
|
||||
|
||||
/**
|
||||
* Return capabilities (fetched lazily, cached thereafter).
|
||||
* Always resolves — falls back to DEFAULT_CAPS on network error.
|
||||
*/
|
||||
export async function getCapabilities() {
|
||||
if (_caps) return _caps;
|
||||
if (!_fetchPromise) {
|
||||
_fetchPromise = apiService.getConfig()
|
||||
.then(data => { _caps = data || DEFAULT_CAPS; return _caps; })
|
||||
.catch(() => { _caps = DEFAULT_CAPS; return _caps; });
|
||||
}
|
||||
return _fetchPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous check — returns cached value or DEFAULT_CAPS if not yet loaded.
|
||||
*/
|
||||
export function getCachedCapabilities() {
|
||||
return _caps || DEFAULT_CAPS;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the remote provider is configured and healthy.
|
||||
*/
|
||||
export function hasRemote() {
|
||||
return !!(_caps?.remote?.healthy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kick off the fetch immediately at module load time so it's ready when tools need it.
|
||||
*/
|
||||
getCapabilities();
|
||||
|
||||
export default { getCapabilities, getCachedCapabilities, hasRemote };
|
||||
Reference in New Issue
Block a user