Commit 7929072
Add PIL Image support to InferenceClient (#3199)
* Add PIL Image support to InferenceClient
- Add PIL Image to ContentT type hints for type checking
- Update _open_as_binary to handle PIL Images by converting to bytes
- Update _as_url to detect MIME type from PIL Image format
- Update docstrings to indicate PIL Image support for all image methods
- Fixes #3191: Make InferenceClient accept Pillow images
This enables iterative image editing workflows where PIL Images returned
by image_to_image can be directly passed back to image_to_image methods
without the 'Unsupported input type for image' error.
* Make style
* Address comments
* Apply suggestion from @Wauplin
* Apply suggestion from @Wauplin
* Apply style fixes
* Apply suggestions from code review
Co-authored-by: célina <[email protected]>
* add tests
* style
---------
Co-authored-by: Lucain <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: célina <[email protected]>1 parent 7660014 commit 7929072
File tree
4 files changed
+86
-38
lines changed- src/huggingface_hub/inference
- _generated
- tests
4 files changed
+86
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1154 | 1154 | | |
1155 | 1155 | | |
1156 | 1156 | | |
1157 | | - | |
1158 | | - | |
| 1157 | + | |
| 1158 | + | |
1159 | 1159 | | |
1160 | 1160 | | |
1161 | 1161 | | |
| |||
1212 | 1212 | | |
1213 | 1213 | | |
1214 | 1214 | | |
1215 | | - | |
1216 | | - | |
| 1215 | + | |
| 1216 | + | |
1217 | 1217 | | |
1218 | 1218 | | |
1219 | 1219 | | |
| |||
1284 | 1284 | | |
1285 | 1285 | | |
1286 | 1286 | | |
1287 | | - | |
1288 | | - | |
| 1287 | + | |
| 1288 | + | |
1289 | 1289 | | |
1290 | 1290 | | |
1291 | 1291 | | |
| |||
1347 | 1347 | | |
1348 | 1348 | | |
1349 | 1349 | | |
1350 | | - | |
1351 | | - | |
| 1350 | + | |
| 1351 | + | |
1352 | 1352 | | |
1353 | 1353 | | |
1354 | 1354 | | |
| |||
1398 | 1398 | | |
1399 | 1399 | | |
1400 | 1400 | | |
1401 | | - | |
1402 | | - | |
| 1401 | + | |
| 1402 | + | |
1403 | 1403 | | |
1404 | 1404 | | |
1405 | 1405 | | |
| |||
2973 | 2973 | | |
2974 | 2974 | | |
2975 | 2975 | | |
2976 | | - | |
2977 | | - | |
| 2976 | + | |
| 2977 | + | |
2978 | 2978 | | |
2979 | 2979 | | |
2980 | 2980 | | |
| |||
3140 | 3140 | | |
3141 | 3141 | | |
3142 | 3142 | | |
3143 | | - | |
3144 | | - | |
| 3143 | + | |
| 3144 | + | |
3145 | 3145 | | |
3146 | 3146 | | |
3147 | 3147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
| 164 | + | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | | - | |
169 | 168 | | |
170 | 169 | | |
171 | 170 | | |
| |||
186 | 185 | | |
187 | 186 | | |
188 | 187 | | |
189 | | - | |
190 | | - | |
191 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
192 | 203 | | |
193 | 204 | | |
194 | 205 | | |
| |||
202 | 213 | | |
203 | 214 | | |
204 | 215 | | |
205 | | - | |
206 | | - | |
207 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
208 | 228 | | |
209 | 229 | | |
210 | 230 | | |
| |||
Lines changed: 14 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1197 | 1197 | | |
1198 | 1198 | | |
1199 | 1199 | | |
1200 | | - | |
1201 | | - | |
| 1200 | + | |
| 1201 | + | |
1202 | 1202 | | |
1203 | 1203 | | |
1204 | 1204 | | |
| |||
1256 | 1256 | | |
1257 | 1257 | | |
1258 | 1258 | | |
1259 | | - | |
1260 | | - | |
| 1259 | + | |
| 1260 | + | |
1261 | 1261 | | |
1262 | 1262 | | |
1263 | 1263 | | |
| |||
1329 | 1329 | | |
1330 | 1330 | | |
1331 | 1331 | | |
1332 | | - | |
1333 | | - | |
| 1332 | + | |
| 1333 | + | |
1334 | 1334 | | |
1335 | 1335 | | |
1336 | 1336 | | |
| |||
1393 | 1393 | | |
1394 | 1394 | | |
1395 | 1395 | | |
1396 | | - | |
1397 | | - | |
| 1396 | + | |
| 1397 | + | |
1398 | 1398 | | |
1399 | 1399 | | |
1400 | 1400 | | |
| |||
1445 | 1445 | | |
1446 | 1446 | | |
1447 | 1447 | | |
1448 | | - | |
1449 | | - | |
| 1448 | + | |
| 1449 | + | |
1450 | 1450 | | |
1451 | 1451 | | |
1452 | 1452 | | |
| |||
3033 | 3033 | | |
3034 | 3034 | | |
3035 | 3035 | | |
3036 | | - | |
3037 | | - | |
| 3036 | + | |
| 3037 | + | |
3038 | 3038 | | |
3039 | 3039 | | |
3040 | 3040 | | |
| |||
3203 | 3203 | | |
3204 | 3204 | | |
3205 | 3205 | | |
3206 | | - | |
3207 | | - | |
| 3206 | + | |
| 3207 | + | |
3208 | 3208 | | |
3209 | 3209 | | |
3210 | 3210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
803 | 804 | | |
804 | 805 | | |
805 | 806 | | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
806 | 816 | | |
807 | 817 | | |
808 | 818 | | |
| |||
1213 | 1223 | | |
1214 | 1224 | | |
1215 | 1225 | | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
0 commit comments