Views
No views yet
Sebukpor/medical-document-understanding-v2
for CPU inference via llama.cpp.| File | Size | Use case |
|---|---|---|
model-Q4_K_M.gguf | ~2.5 GB | ✅ Recommended — best quality/size for deployment |
model-Q8_0.gguf | ~4.5 GB | Near-lossless, slower |
model-F16.gguf | ~8.5 GB | Reference, too large for free tier |
1from llama_cpp import Llama
2from llama_cpp.llama_chat_format import Qwen2VLChatHandler
3
4chat_handler = Qwen2VLChatHandler(
5 clip_model_path="mmproj-model-f16.gguf" # vision encoder (see below)
6)
7
8llm = Llama(
9 model_path="model-Q4_K_M.gguf",
10 chat_handler=chat_handler,
11 n_ctx=2048,
12 n_threads=2, # HF free tier has 2 vCPU
13 verbose=False,
14)
15
16import base64
17with open("opd_form.jpg", "rb") as f:
18 img_b64 = base64.b64encode(f.read()).decode()
19
20response = llm.create_chat_completion(
21 messages=[
22 {
23 "role": "system",
24 "content": "You are an expert Medical Transcription AI. Extract all information into structured JSON."
25 },
26 {
27 "role": "user",
28 "content": [
29 {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{img_b64}"}},
30 {"type": "text", "text": "Extract all information from this medical OPD form into structured JSON."}
31 ]
32 }
33 ],
34 max_tokens=1024,
35 temperature=0.0,
36)
37print(response["choices"][0]["message"]["content"])app.py included in this repo for a ready-to-deploy Gradio app.Qwen/Qwen3.5-4B on handwritten Indian medical OPD forms.