This project generates a synthetic dataset, trains a multi-label XGBoost classifier, and exports it to ONNX format for use in web applications.
1import * as ort from 'onnxruntime-web';
2
3// Feature list must match model_features.json order
4const FEATURES = [
5 'Age', 'Sex',
6 'insomnia', 'fatigue', 'panic', 'panic_sleep', 'social_withdrawal',
7 'mood_swings', 'anhedonia', 'rumination', 'appetite_change', 'concentration_issues',
8 'self_harm_ideation', 'irritability', 'withdrawal', 'anxiety_general', 'psychomotor',
9 'suicidal_thoughts', 'hopelessness', 'panic_physical'
10];
11
12async function predictMentalHealth(inputs) {
13 try {
14 // 1. Create session
15 const session = await ort.InferenceSession.create('/models/mental_health_model.onnx');
16
17 // 2. Prepare input tensor
18 // Inputs must be float32
19 const inputData = Float32Array.from(FEATURES.map(f => inputs[f] || 0));
20
21 // Shape: [1, 20] (Batch size 1, 20 features)
22 const tensor = new ort.Tensor('float32', inputData, [1, 20]);
23
24 // 3. Run inference
25 // Feeds: object key 'float_input' must match the name defined in python script
26 const feeds = { float_input: tensor };
27 const results = await session.run(feeds);
28
29 // 4. Parse results
30 // Output name depends on sklearn conversion, usually 'probabilities' or 'output_probability'
31 // For MultiOutput, it might return multiple outputs or a combined sequence.
32 // Check results object keys. Usually: results.label, results.probabilities
33
34 console.log("Prediction Results:", results);
35
36 // Note: The structure of 'results' varies by ONNX converter version.
37 // You might get a map or a list of tensors. Inspect 'results' in console.
38
39 return results;
40
41 } catch (e) {
42 console.error("Inference failed:", e);
43 }
44}
1from huggingface_hub import hf_hub_download
2
3model_path = hf_hub_download(repo_id="<your-username>/mental-health-xgboost-onnx", filename="mental_health_model.onnx")
4print(f"Model downloaded to: {model_path}")