This model is designed to take structured output from a primary ML classifier (which provides findings like "Atrial Fibrillation: 82% confidence, Present") and synthesize it into a coherent, human-readable clinical report, complete with an impression, detailed analysis, and clinical recommendations.
This model follows a standard instruction format. Provide the instruction and the structured input to get a clinical report.
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_name = "OussamaEL/MedGemma-4B-ECG"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 torch_dtype=torch.bfloat16,
9 device_map="auto",
10)
11
12# Alpaca prompt format is required
13alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
14### Instruction:
15{}
16### Input:
17{}
18### Response:
19{}"""
20
21instruction = "You are a medical AI assistant specializing in ECG interpretation. Analyze the ECG findings and patient context to generate a clinical report."
22
23input_text = """ECG FINDINGS:
24- Atrial Fibrillation (AFIB): 95% confidence, Present
25- Sinus Tachycardia (STACH): 88% confidence, Present
26
27PATIENT CONTEXT:
2868-year-old male with diabetes and hypertension presents with 2 days of worsening shortness of breath and leg swelling."""
29
30inputs = tokenizer(
31 alpaca_prompt.format(instruction, input_text, ""),
32 return_tensors="pt"
33).to("cuda")
34
35outputs = model.generate(**inputs, max_new_tokens=256)
36print(tokenizer.decode(outputs[0], skip_special_tokens=True).split("### Response:")[1].strip())
This model is intended for research and development purposes and is not a substitute for professional medical advice.