Skip to content

Commit 80cf756

Browse files
ndebuhrVaibhavs10Wauplin
authored
Simplify usage of the CXR Foundation Google Health AI model (#1222)
This small PR incrementally improves developer experience, by doing a pip-install-from-git installation and more broadly condensing the Hugging Face Hub usage snippet. --------- Co-authored-by: vb <[email protected]> Co-authored-by: Lucain <[email protected]> Co-authored-by: Lucain <[email protected]>
1 parent f0361f3 commit 80cf756

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

packages/tasks/src/model-libraries-snippets.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,14 @@ retriever = BM25HF.load_from_hub("${model.id}")`,
110110
];
111111

112112
export const cxr_foundation = (): string[] => [
113-
`!git clone https://github.com/Google-Health/cxr-foundation.git
114-
import tensorflow as tf, sys, requests
115-
sys.path.append('cxr-foundation/python/')
113+
`# pip install git+https://github.com/Google-Health/cxr-foundation.git#subdirectory=python
116114
117-
# Install dependencies
118-
major_version = tf.__version__.rsplit(".", 1)[0]
119-
!pip install tensorflow-text=={major_version} pypng && pip install --no-deps pydicom hcls_imaging_ml_toolkit retrying
120-
121-
# Load image (Stillwaterising, CC0, via Wikimedia Commons)
115+
# Load image as grayscale (Stillwaterising, CC0, via Wikimedia Commons)
116+
import requests
122117
from PIL import Image
123118
from io import BytesIO
124119
image_url = "https://upload.wikimedia.org/wikipedia/commons/c/c8/Chest_Xray_PA_3-8-2010.png"
125-
response = requests.get(image_url, headers={'User-Agent': 'Demo'}, stream=True)
126-
response.raw.decode_content = True # Ensure correct decoding
127-
img = Image.open(BytesIO(response.content)).convert('L') # Convert to grayscale
120+
img = Image.open(requests.get(image_url, headers={'User-Agent': 'Demo'}, stream=True).raw).convert('L')
128121
129122
# Run inference
130123
from clientside.clients import make_hugging_face_client

0 commit comments

Comments
 (0)