CoolFace
Modelpublic

joelmontavon/fhir4px-model-webllm

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
Model Card

fhir4px-model Integration

This directory contains the integration package required to use the fhir4px-model and lookup table inside a web application.

1. Hosting Requirements

Before using this integration, you need to host the compiled model artifacts:

  1. 1.Model Weights: Host the contents of dist/fhir4px-q4f16_1-MLC/ on a CDN or a HuggingFace model repository.
  2. 2.WebGPU WASM: Host dist/libs/fhir4px-q4f16_1-webgpu.wasm on a CDN.
  3. 3.Lookup Table: Copy dist/lookup.json into your web application's static assets or src directory.

Once hosted, update the URLs in src/integration/config.ts to point to your live assets.

2. Dependencies

You will need the @mlc.ai/web-llm package in your web project.

bash
npm install @mlc.ai/web-llm

3. Usage Example

Here is how you use the pipeline to translate FHIR codes in your app:

typescript
import { FhirLookup, initializeLLM, translateClinicalTerm } from './integration';
// Import your bundled lookup table
import lookupJson from './lookup.json';

async function main() {
  // 1. Initialize the local, deterministic lookup table
  const lookup = new FhirLookup(lookupJson);

  // 2. Initialize the WebGPU LLM for fallbacks
  console.log("Downloading and initializing model...");
  const engine = await initializeLLM((report) => {
    console.log(`Loading: ${report.text}`);
  });

  // 3. Translate a known code (will be fast, no LLM required)
  const knownTerm = await translateClinicalTerm(
    engine, 
    lookup, 
    "O00.20", 
    "ICD10CM", 
    "Ovarian pregnancy without intrauterine pregnancy"
  );
  console.log("Known term:", knownTerm); // Output: "ovarian pregnancy"

  // 4. Translate an unknown code (will fallback to WebGPU LLM)
  const unknownTerm = await translateClinicalTerm(
    engine, 
    lookup, 
    "UNKNOWN-999", 
    "SNOMEDCT_US", 
    "Acute myocardial infarction of inferolateral wall"
  );
  console.log("Unknown term:", unknownTerm); // Output: "Heart attack (myocardial infarction)"
}

main();