mirror of
https://github.com/ruvnet/RuView.git
synced 2026-04-28 05:59:32 +00:00
* feat: RVF training pipeline & UI integration (ADR-036) Implement full model training, management, and inference pipeline: Backend (Rust): - recording.rs: CSI recording API (start/stop/list/download/delete) - model_manager.rs: RVF model loading, LoRA profile switching, model library - training_api.rs: Training API with WebSocket progress streaming, simulated training mode with realistic loss curves, auto-RVF export on completion - main.rs: Wire new modules, recording hooks in all CSI paths, data dirs UI (new components): - ModelPanel.js: Dark-mode model library with load/unload, LoRA dropdown - TrainingPanel.js: Recording controls, training config, live Canvas charts - model.service.js: Model REST API client with events - training.service.js: Training + recording API client with WebSocket progress UI (enhancements): - LiveDemoTab: Model selector, LoRA profile switcher, A/B split view toggle, training quick-panel with 60s recording shortcut - SettingsPanel: Full dark mode conversion (issue #92), model configuration (device, threads, auto-load), training configuration (epochs, LR, patience) - PoseDetectionCanvas: 10-frame pose trail with ghost keypoints and motion trajectory lines, cyan trail toggle button - pose.service.js: Model-inference confidence thresholds UI (plumbing): - index.html: Training tab (8th tab) - app.js: Panel initialization and tab routing - style.css: ~250 lines of training/model panel dark-mode styles 191 Rust tests pass, 0 failures. Closes #92. Refs: ADR-036, #93 Co-Authored-By: claude-flow <ruv@ruv.net> * fix: real RuVector training pipeline + UI service fixes Training pipeline (training_api.rs): - Replace simulated training with real signal-based training loop - Load actual CSI data from .csi.jsonl recordings or live frame history - Extract 180 features per frame: subcarrier amplitudes, temporal variance, Goertzel frequency analysis (9 bands), motion gradients, global stats - Train calibrated linear CSI-to-pose mapping via mini-batch gradient descent with L2 regularization (ridge regression), Xavier init, cosine LR decay - Self-supervised: teacher targets from derive_pose_from_sensing() heuristics - Real validation metrics: MSE and PCK@0.2 on 80/20 train/val split - Export trained .rvf with real weights, feature normalization stats, witness - Add infer_pose_from_model() for live inference from trained model - 16 new tests covering features, training, inference, serialization UI fixes: - Fix double-URL bug in model.service.js and training.service.js (buildApiUrl was called twice — once in service, once in apiService) - Fix route paths to match Rust backend (/api/v1/train/*, /api/v1/recording/*) - Fix request body formats (session_name, nested config object) - Fix top-level await in LiveDemoTab.js blocking module graph - Dynamic imports for ModelPanel/TrainingPanel in app.js - Center nav tabs with flex-wrap for 8-tab layout Co-Authored-By: claude-flow <ruv@ruv.net> * fix: WebSocket onOpen race condition, data source indicators, auto-start pose detection - Fix WebSocket onOpen race condition in websocket.service.js where setupEventHandlers replaced onopen after socket was already open, preventing pose service from receiving connection signal - Add 4-state data source indicator (LIVE/SIMULATED/RECONNECTING/OFFLINE) across Dashboard, Sensing, and Live Demo tabs via sensing.service.js - Add hot-plug ESP32 auto-detection in sensing server (auto mode runs both UDP listener and simulation, switches on ESP32_TIMEOUT) - Auto-start pose detection when backend is reachable - Hide duplicate PoseDetectionCanvas controls when enableControls=false - Add standalone Demo button in LiveDemoTab for offline animated demo - Add data source banner and status styling Co-Authored-By: claude-flow <ruv@ruv.net>
152 lines
4.4 KiB
JavaScript
152 lines
4.4 KiB
JavaScript
// Model Service for WiFi-DensePose UI
|
|
// Manages model loading, listing, LoRA profiles, and lifecycle events.
|
|
|
|
import { apiService } from './api.service.js';
|
|
|
|
export class ModelService {
|
|
constructor() {
|
|
this.activeModel = null;
|
|
this.listeners = {};
|
|
this.logger = this.createLogger();
|
|
}
|
|
|
|
createLogger() {
|
|
return {
|
|
debug: (...args) => console.debug('[MODEL-DEBUG]', new Date().toISOString(), ...args),
|
|
info: (...args) => console.info('[MODEL-INFO]', new Date().toISOString(), ...args),
|
|
warn: (...args) => console.warn('[MODEL-WARN]', new Date().toISOString(), ...args),
|
|
error: (...args) => console.error('[MODEL-ERROR]', new Date().toISOString(), ...args)
|
|
};
|
|
}
|
|
|
|
// --- Event emitter helpers ---
|
|
|
|
on(event, callback) {
|
|
if (!this.listeners[event]) {
|
|
this.listeners[event] = [];
|
|
}
|
|
this.listeners[event].push(callback);
|
|
return () => this.off(event, callback);
|
|
}
|
|
|
|
off(event, callback) {
|
|
if (!this.listeners[event]) return;
|
|
this.listeners[event] = this.listeners[event].filter(cb => cb !== callback);
|
|
}
|
|
|
|
emit(event, data) {
|
|
if (!this.listeners[event]) return;
|
|
this.listeners[event].forEach(cb => {
|
|
try { cb(data); } catch (err) { this.logger.error('Listener error', { event, err }); }
|
|
});
|
|
}
|
|
|
|
// --- API methods ---
|
|
|
|
async listModels() {
|
|
try {
|
|
const data = await apiService.get('/api/v1/models');
|
|
this.logger.info('Listed models', { count: data?.models?.length ?? 0 });
|
|
return data;
|
|
} catch (error) {
|
|
this.logger.error('Failed to list models', { error: error.message });
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async getModel(id) {
|
|
try {
|
|
const data = await apiService.get(`/api/v1/models/${encodeURIComponent(id)}`);
|
|
return data;
|
|
} catch (error) {
|
|
this.logger.error('Failed to get model', { id, error: error.message });
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async loadModel(modelId) {
|
|
try {
|
|
this.logger.info('Loading model', { modelId });
|
|
const data = await apiService.post('/api/v1/models/load', { model_id: modelId });
|
|
this.activeModel = { model_id: modelId };
|
|
this.emit('model-loaded', { model_id: modelId });
|
|
return data;
|
|
} catch (error) {
|
|
this.logger.error('Failed to load model', { modelId, error: error.message });
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async unloadModel() {
|
|
try {
|
|
this.logger.info('Unloading model');
|
|
const data = await apiService.post('/api/v1/models/unload', {});
|
|
this.activeModel = null;
|
|
this.emit('model-unloaded', {});
|
|
return data;
|
|
} catch (error) {
|
|
this.logger.error('Failed to unload model', { error: error.message });
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async getActiveModel() {
|
|
try {
|
|
const data = await apiService.get('/api/v1/models/active');
|
|
this.activeModel = data || null;
|
|
return this.activeModel;
|
|
} catch (error) {
|
|
if (error.status === 404) {
|
|
this.activeModel = null;
|
|
return null;
|
|
}
|
|
this.logger.error('Failed to get active model', { error: error.message });
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async activateLoraProfile(modelId, profileName) {
|
|
try {
|
|
this.logger.info('Activating LoRA profile', { modelId, profileName });
|
|
const data = await apiService.post(
|
|
'/api/v1/models/lora/activate',
|
|
{ model_id: modelId, profile_name: profileName }
|
|
);
|
|
this.emit('lora-activated', { model_id: modelId, profile: profileName });
|
|
return data;
|
|
} catch (error) {
|
|
this.logger.error('Failed to activate LoRA', { modelId, profileName, error: error.message });
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async getLoraProfiles() {
|
|
try {
|
|
const data = await apiService.get('/api/v1/models/lora/profiles');
|
|
return data?.profiles ?? [];
|
|
} catch (error) {
|
|
this.logger.error('Failed to get LoRA profiles', { error: error.message });
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async deleteModel(id) {
|
|
try {
|
|
this.logger.info('Deleting model', { id });
|
|
const data = await apiService.delete(`/api/v1/models/${encodeURIComponent(id)}`);
|
|
return data;
|
|
} catch (error) {
|
|
this.logger.error('Failed to delete model', { id, error: error.message });
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
dispose() {
|
|
this.listeners = {};
|
|
this.activeModel = null;
|
|
this.logger.info('ModelService disposed');
|
|
}
|
|
}
|
|
|
|
// Create singleton instance
|
|
export const modelService = new ModelService();
|