MCPcopy
hub / github.com/lm-sys/FastChat / load_image

Function load_image

fastchat/utils.py:362–380  ·  view source on GitHub ↗
(image_file)

Source from the content-addressed store, hash-verified

360
361
362def load_image(image_file):
363 from PIL import Image
364 import requests
365
366 image = None
367
368 if image_file.startswith("http://") or image_file.startswith("https://"):
369 timeout = int(os.getenv("REQUEST_TIMEOUT", "3"))
370 response = requests.get(image_file, timeout=timeout)
371 image = Image.open(BytesIO(response.content))
372 elif image_file.lower().endswith(("png", "jpg", "jpeg", "webp", "gif")):
373 image = Image.open(image_file)
374 elif image_file.startswith("data:"):
375 image_file = image_file.split(",")[1]
376 image = Image.open(BytesIO(base64.b64decode(image_file)))
377 else:
378 image = Image.open(BytesIO(base64.b64decode(image_file)))
379
380 return image

Callers 2

bot_responseFunction · 0.90
generate_streamMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…