medgemma 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
medgemma/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.0"
1
+ __version__ = "0.1.1"
@@ -0,0 +1,307 @@
1
+ Metadata-Version: 2.4
2
+ Name: medgemma
3
+ Version: 0.1.1
4
+ Summary: Medical AI on Apple Silicon – MedGemma 1.5 4B via MLX
5
+ Author: chiboko
6
+ License-Expression: MIT
7
+ Keywords: ai,apple-silicon,medgemma,medical,mlx
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Healthcare Industry
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: click>=8.0
16
+ Requires-Dist: mlx-vlm>=0.3.10
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest-mock; extra == 'dev'
19
+ Requires-Dist: pytest>=7.0; extra == 'dev'
20
+ Description-Content-Type: text/markdown
21
+
22
+ # medgemma
23
+
24
+ **Medical AI on Apple Silicon — MedGemma 1.5 4B via MLX**
25
+
26
+ [![PyPI version](https://img.shields.io/pypi/v/medgemma)](https://pypi.org/project/medgemma/)
27
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue)](https://python.org)
28
+ [![Apple Silicon](https://img.shields.io/badge/platform-Apple%20Silicon-black?logo=apple)](https://support.apple.com/en-us/116943)
29
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
30
+
31
+ > [!WARNING]
32
+ > **Medical Disclaimer** — This tool is for **informational and educational purposes only**. It is NOT a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare provider for medical decisions. Never disregard professional medical advice because of something generated by this tool.
33
+
34
+ ## What is MedGemma?
35
+
36
+ MedGemma is a command-line tool and Python library that runs Google's [MedGemma 1.5 4B](https://huggingface.co/google/medgemma-4b-it) medical AI model locally on your Mac. It uses Apple's [MLX framework](https://ml-explore.github.io/mlx/) to run entirely on your Apple Silicon GPU — no cloud API, no data leaves your machine. Ask medical questions, analyze medical images, and get evidence-based responses, all from your terminal.
37
+
38
+ ## Requirements
39
+
40
+ - **Apple Silicon Mac** (M1, M2, M3, or M4)
41
+ - **Python 3.10** or newer
42
+ - **~4 GB disk space** for the quantized model weights
43
+ - **macOS** (the only supported platform)
44
+
45
+ ## Quick Start
46
+
47
+ ### 1. Install
48
+
49
+ ```bash
50
+ pip install medgemma
51
+ ```
52
+
53
+ Or with [uv](https://docs.astral.sh/uv/):
54
+
55
+ ```bash
56
+ uv pip install medgemma
57
+ ```
58
+
59
+ ### 2. Hugging Face authentication
60
+
61
+ The model weights are hosted on Hugging Face under [google/medgemma-4b-it](https://huggingface.co/google/medgemma-4b-it). Before downloading, you need to:
62
+
63
+ 1. Create a [Hugging Face account](https://huggingface.co/join) (free)
64
+ 2. Visit the [model page](https://huggingface.co/google/medgemma-4b-it) and accept Google's license agreement
65
+ 3. Log in locally:
66
+
67
+ ```bash
68
+ pip install huggingface-hub
69
+ huggingface-cli login
70
+ ```
71
+
72
+ You only need to do this once.
73
+
74
+ ### 3. Download the model
75
+
76
+ ```bash
77
+ medgemma setup
78
+ ```
79
+
80
+ This downloads the MedGemma 4B model from Hugging Face, converts it to 4-bit quantized MLX format, and caches it at `~/.medgemma/model`. You only need to do this once.
81
+
82
+ ### 4. Ask a question
83
+
84
+ ```bash
85
+ medgemma ask "What are the common symptoms of type 2 diabetes?"
86
+ ```
87
+
88
+ Example output:
89
+
90
+ ```
91
+ The common symptoms of type 2 diabetes include:
92
+
93
+ * **Increased thirst (polydipsia):** You may feel thirsty more often than usual.
94
+ * **Frequent urination (polyuria):** You may need to urinate more often,
95
+ especially at night.
96
+ * **Increased hunger (polyphagia):** You may feel hungry even after eating.
97
+ * **Unexplained weight loss:** You may lose weight without trying.
98
+ * **Fatigue:** You may feel tired and lacking energy.
99
+ * **Blurred vision:** High blood sugar can affect the lenses of your eyes.
100
+ * **Slow-healing sores or frequent infections:** High blood sugar can impair
101
+ your body's ability to heal.
102
+ * **Numbness or tingling in hands or feet:** This can be a sign of nerve
103
+ damage (neuropathy).
104
+ * **Areas of darkened skin:** Particularly in the armpits and neck
105
+ (acanthosis nigricans).
106
+
107
+ It is important to note that many people with type 2 diabetes may not experience
108
+ any symptoms in the early stages. Regular check-ups and blood sugar screenings
109
+ are recommended, especially if you have risk factors.
110
+
111
+ **Disclaimer:** I am an AI assistant and cannot provide medical advice. Please
112
+ consult a healthcare professional for diagnosis and treatment.
113
+ ```
114
+
115
+ ## Image Analysis
116
+
117
+ Analyze medical images by passing `--image`:
118
+
119
+ ```bash
120
+ medgemma ask "Describe this chest X-ray" --image chest_xray.png
121
+ ```
122
+
123
+ Example output:
124
+
125
+ ```
126
+ The chest X-ray shows the following findings:
127
+
128
+ * **Heart size:** The heart appears to be within normal limits in size.
129
+ * **Lungs:** The lung fields appear clear, without any obvious consolidation,
130
+ effusion, or pneumothorax.
131
+ * **Mediastinum:** The mediastinal contours appear normal.
132
+ * **Bones:** No acute bony abnormalities are identified.
133
+
134
+ **Overall impression:** The chest X-ray appears unremarkable, with no acute
135
+ cardiopulmonary abnormality identified.
136
+
137
+ **Disclaimer:** I am an AI and this is not a radiological report. Please
138
+ consult a qualified radiologist for proper interpretation.
139
+ ```
140
+
141
+ ## CLI Reference
142
+
143
+ ### `medgemma ask`
144
+
145
+ Send a prompt (and optional image) to the model.
146
+
147
+ ```bash
148
+ medgemma ask PROMPT [OPTIONS]
149
+ ```
150
+
151
+ | Option | Description |
152
+ |---|---|
153
+ | `--image PATH` | Path to an image file to analyze |
154
+ | `--max-tokens INT` | Maximum tokens to generate (default: 512) |
155
+ | `--temperature FLOAT` | Sampling temperature (default: 0.1) |
156
+ | `--model-path PATH` | Path to a local MLX model directory |
157
+ | `--json` | Output full response as JSON with stats |
158
+ | `--no-stream` | Disable streaming, print all at once |
159
+
160
+ ### `medgemma setup`
161
+
162
+ Download and prepare the model.
163
+
164
+ ```bash
165
+ medgemma setup [OPTIONS]
166
+ ```
167
+
168
+ | Option | Description |
169
+ |---|---|
170
+ | `--local-path PATH` | Use an already-converted local model instead of downloading |
171
+ | `--force` | Re-download and overwrite existing cached model |
172
+
173
+ ### `medgemma info`
174
+
175
+ Show model status and cache location.
176
+
177
+ ```bash
178
+ medgemma info
179
+ ```
180
+
181
+ Example output:
182
+
183
+ ```
184
+ Cache directory: /Users/you/.medgemma/model
185
+ Model in cache: yes
186
+ Model loaded: no
187
+ ```
188
+
189
+ ### `medgemma --version`
190
+
191
+ Print the installed version.
192
+
193
+ ## Python API
194
+
195
+ ### Basic usage
196
+
197
+ ```python
198
+ from medgemma import MedGemma
199
+
200
+ mg = MedGemma()
201
+ response = mg.ask("What are symptoms of diabetes?")
202
+ print(response.text)
203
+ ```
204
+
205
+ ### Image analysis
206
+
207
+ ```python
208
+ response = mg.ask("Describe this X-ray", image="chest_xray.png")
209
+ print(response.text)
210
+ ```
211
+
212
+ ### Streaming
213
+
214
+ ```python
215
+ for chunk in mg.stream("Explain hypertension"):
216
+ print(chunk, end="", flush=True)
217
+ ```
218
+
219
+ ### Response object
220
+
221
+ `MedGemma.ask()` returns a `Response` dataclass with these fields:
222
+
223
+ | Field | Type | Description |
224
+ |---|---|---|
225
+ | `text` | `str` | The generated response text |
226
+ | `prompt_tokens` | `int` | Number of tokens in the prompt |
227
+ | `completion_tokens` | `int` | Number of tokens generated |
228
+ | `tokens_per_second` | `float` | Generation speed |
229
+ | `elapsed_seconds` | `float` | Total generation time |
230
+
231
+ ```python
232
+ response = mg.ask("What is aspirin used for?")
233
+ print(response.text)
234
+ print(f"{response.completion_tokens} tokens in {response.elapsed_seconds:.1f}s")
235
+ print(f"Speed: {response.tokens_per_second:.1f} tok/s")
236
+ ```
237
+
238
+ ### Custom model path and parameters
239
+
240
+ ```python
241
+ mg = MedGemma(
242
+ model_path="/path/to/local/mlx-model",
243
+ max_tokens=1024,
244
+ temperature=0.3,
245
+ )
246
+ ```
247
+
248
+ ### Release model from memory
249
+
250
+ ```python
251
+ mg.unload()
252
+ ```
253
+
254
+ ## JSON Output
255
+
256
+ Use `--json` to get structured output with generation stats:
257
+
258
+ ```bash
259
+ medgemma ask "What is hypertension?" --json
260
+ ```
261
+
262
+ ```json
263
+ {
264
+ "text": "Hypertension, also known as high blood pressure, is a chronic medical condition...",
265
+ "completion_tokens": 248,
266
+ "tokens_per_second": 32.5,
267
+ "elapsed_seconds": 7.6
268
+ }
269
+ ```
270
+
271
+ ## How It Works
272
+
273
+ 1. **Model download** — `medgemma setup` downloads Google's [MedGemma 1.5 4B-IT](https://huggingface.co/google/medgemma-4b-it) from Hugging Face.
274
+ 2. **Quantization** — The model is converted to 4-bit quantized MLX format, reducing size from ~8 GB to ~4 GB while preserving quality.
275
+ 3. **Local inference** — All inference runs on your Apple Silicon GPU via the [MLX](https://ml-explore.github.io/mlx/) framework. No data is sent to any server.
276
+ 4. **Lazy loading** — The model loads into memory only on the first `ask()` or `stream()` call, and stays loaded for subsequent requests.
277
+
278
+ ## Troubleshooting
279
+
280
+ ### "Not running on Apple Silicon"
281
+
282
+ MedGemma requires an Apple Silicon Mac (M1/M2/M3/M4). It cannot run on Intel Macs or other platforms. The MLX framework only supports Apple's ARM-based chips.
283
+
284
+ ### Model download fails
285
+
286
+ - Make sure you've accepted the license at [google/medgemma-4b-it](https://huggingface.co/google/medgemma-4b-it) and logged in with `huggingface-cli login`
287
+ - Check your internet connection
288
+ - Ensure you have ~4 GB of free disk space
289
+ - Try again with `medgemma setup --force`
290
+ - If you're behind a firewall, download the model manually and use `medgemma setup --local-path /path/to/model`
291
+
292
+ ### Out of memory
293
+
294
+ The 4-bit quantized model needs approximately 4 GB of unified memory. If you're running low:
295
+
296
+ - Close other memory-intensive applications
297
+ - Use `--max-tokens` with a lower value to limit output length
298
+ - Call `mg.unload()` in Python when you're done to free memory
299
+
300
+ ### Model loads slowly on first run
301
+
302
+ The first `ask` call loads the model into GPU memory, which can take several seconds. Subsequent calls reuse the loaded model and are much faster.
303
+
304
+ ---
305
+
306
+ > [!WARNING]
307
+ > **Medical Disclaimer** — This tool is for **informational and educational purposes only**. It does not provide medical advice, diagnosis, or treatment. The outputs are generated by an AI model and may be inaccurate or incomplete. Always seek the advice of a qualified healthcare provider with any questions regarding a medical condition.
@@ -1,13 +1,13 @@
1
1
  medgemma/__init__.py,sha256=G29Y0KqJ6cXMqqwnBFypNR5wSazaUlIJcOLjccgHSns,235
2
2
  medgemma/__main__.py,sha256=bwb3cqcddGbAvdwq9sDSBqhmCjoZG4BaH-CIkpSgsb4,65
3
3
  medgemma/_compat.py,sha256=rwxytYiARMIa24EB42MMhnVbKRD5LceMFWrDHKV_rW4,727
4
- medgemma/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
4
+ medgemma/_version.py,sha256=rnObPjuBcEStqSO0S6gsdS_ot8ITOQjVj_-P1LUUYpg,22
5
5
  medgemma/cli.py,sha256=cjFICqjfyZeCvzC-7A3FW2bbsm-YpXhmq25St1k_4ck,2869
6
6
  medgemma/client.py,sha256=s_urpYSmD7_vcmIo-yF1LOomNtJFQv8whK4qZkXcUzY,5183
7
7
  medgemma/config.py,sha256=bfS-LED3fCdCVKNV4qpJUU5r5kUGfOaKr9rnypfBUiE,672
8
8
  medgemma/convert.py,sha256=1EpvMtRG7p8WNeRxsPGtxG2saAidsEdRiqWgnSpKygc,2889
9
9
  medgemma/model.py,sha256=7Vuhxry8CMXdKxTRoiRqXHF7lx7rPNQ7Vqa3lF8SULQ,1920
10
- medgemma-0.1.0.dist-info/METADATA,sha256=1ZTUGvR2jAMgp_kZvHgePoYO4VpbjhDF6kmtPPOl_Mo,1146
11
- medgemma-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
12
- medgemma-0.1.0.dist-info/entry_points.txt,sha256=xdJRJThjQNLeVqUIw0vERv9kReFa15FhAoX2X-0x2ck,46
13
- medgemma-0.1.0.dist-info/RECORD,,
10
+ medgemma-0.1.1.dist-info/METADATA,sha256=OMuxNyQ56C2ESuGigS2SehD-G4neHgX8bPaJiq0Xhq8,9828
11
+ medgemma-0.1.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
12
+ medgemma-0.1.1.dist-info/entry_points.txt,sha256=xdJRJThjQNLeVqUIw0vERv9kReFa15FhAoX2X-0x2ck,46
13
+ medgemma-0.1.1.dist-info/RECORD,,
@@ -1,49 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: medgemma
3
- Version: 0.1.0
4
- Summary: Medical AI on Apple Silicon – MedGemma 1.5 4B via MLX
5
- Author: chiboko
6
- License-Expression: MIT
7
- Keywords: ai,apple-silicon,medgemma,medical,mlx
8
- Classifier: Development Status :: 3 - Alpha
9
- Classifier: Intended Audience :: Healthcare Industry
10
- Classifier: Intended Audience :: Science/Research
11
- Classifier: Operating System :: MacOS
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
- Requires-Python: >=3.10
15
- Requires-Dist: click>=8.0
16
- Requires-Dist: mlx-vlm>=0.3.10
17
- Provides-Extra: dev
18
- Requires-Dist: pytest-mock; extra == 'dev'
19
- Requires-Dist: pytest>=7.0; extra == 'dev'
20
- Description-Content-Type: text/markdown
21
-
22
- # medgemma
23
-
24
- Medical AI on Apple Silicon – MedGemma 1.5 4B via MLX.
25
-
26
- ## Install
27
-
28
- ```bash
29
- pip install medgemma
30
- ```
31
-
32
- ## Usage
33
-
34
- ```python
35
- from medgemma import MedGemma
36
-
37
- mg = MedGemma()
38
- response = mg.ask("What are symptoms of diabetes?")
39
- print(response.text)
40
- ```
41
-
42
- ### CLI
43
-
44
- ```bash
45
- medgemma ask "What are symptoms of diabetes?"
46
- medgemma ask "Describe this X-ray" --image xray.png
47
- medgemma setup
48
- medgemma info
49
- ```