@@ -96,23 +96,26 @@ retriever = BM25HF.load_from_hub("${model.id}")`,
96
96
] ;
97
97
98
98
export const cxr_foundation = ( model : ModelData ) : string [ ] => [
99
- `# Install library
100
- !git clone https://github.com/Google-Health/cxr-foundation.git
101
- import tensorflow as tf, sys
99
+ `!git clone https://github.com/Google-Health/cxr-foundation.git
100
+ import tensorflow as tf, sys, requests
102
101
sys.path.append('cxr-foundation/python/')
103
102
104
103
# Install dependencies
105
104
major_version = tf.__version__.rsplit(".", 1)[0]
106
105
!pip install tensorflow-text=={major_version} pypng && pip install --no-deps pydicom hcls_imaging_ml_toolkit retrying
107
106
108
- # Run inference
107
+ # Load image (Stillwaterising, CC0, via Wikimedia Commons)
109
108
from PIL import Image
110
- from clientside.clients import make_hugging_face_client
109
+ from io import BytesIO
110
+ image_url = "https://upload.wikimedia.org/wikipedia/commons/c/c8/Chest_Xray_PA_3-8-2010.png"
111
+ response = requests.get(image_url, headers={'User-Agent': 'Demo'}, stream=True)
112
+ response.raw.decode_content = True # Ensure correct decoding
113
+ img = Image.open(BytesIO(response.content)).convert('L') # Convert to grayscale
111
114
115
+ # Run inference
116
+ from clientside.clients import make_hugging_face_client
112
117
cxr_client = make_hugging_face_client('cxr_model')
113
- !wget -nc -q https://upload.wikimedia.org/wikipedia/commons/c/c8/Chest_Xray_PA_3-8-2010.png
114
-
115
- print(cxr_client.get_image_embeddings_from_images([Image.open("Chest_Xray_PA_3-8-2010.png")]))` ,
118
+ print(cxr_client.get_image_embeddings_from_images([img]))` ,
116
119
] ;
117
120
118
121
export const depth_anything_v2 = ( model : ModelData ) : string [ ] => {
@@ -189,34 +192,25 @@ focallength_px = prediction["focallength_px"]`;
189
192
} ;
190
193
191
194
export const derm_foundation = ( model : ModelData ) : string [ ] => [
192
- `from PIL import Image
193
- from io import BytesIO
194
- from huggingface_hub import from_pretrained_keras
195
- import tensorflow as tf
196
- import requests
195
+ `from huggingface_hub import from_pretrained_keras
196
+ import tensorflow as tf, requests
197
197
198
- response = requests.get("https://storage.googleapis.com/dx-scin-public-data/dataset/images/3445096909671059178.png")
199
- # Load the image into a PIL Image object
200
- image = Image.open(response.raw)
201
-
202
- buf = BytesIO()
203
- image.convert("RGB").save(buf, "PNG")
204
- image_bytes = buf.getvalue()
205
- # Format input
198
+ # Load and format input
199
+ IMAGE_URL = "https://storage.googleapis.com/dx-scin-public-data/dataset/images/3445096909671059178.png"
206
200
input_tensor = tf.train.Example(
207
201
features=tf.train.Features(
208
202
feature={
209
203
"image/encoded": tf.train.Feature(
210
- bytes_list=tf.train.BytesList(value=[image_bytes ])
204
+ bytes_list=tf.train.BytesList(value=[requests.get(IMAGE_URL, stream=True).content ])
211
205
)
212
206
}
213
207
)
214
208
).SerializeToString()
215
209
210
+ # Load model and run inference
216
211
loaded_model = from_pretrained_keras("google/derm-foundation")
217
-
218
212
infer = loaded_model.signatures["serving_default"]
219
- output = infer(inputs=tf.constant([input_tensor]))`,
213
+ print( infer(inputs=tf.constant([input_tensor]) ))`,
220
214
]
221
215
222
216
const diffusersDefaultPrompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" ;
0 commit comments