Spaces:
Runtime error
Runtime error
Download utils.py from ultron1996/multimodal_rag: direct link, hf CLI and curl.
- Browser
- Download file 585 Bytes
-
https://huggingface.co/spaces/ultron1996/multimodal_rag/resolve/main/utils.py
- Command line
-
hf download hf://spaces/ultron1996/multimodal_rag/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/ultron1996/multimodal_rag/resolve/main/utils.py
585 Bytes
| import base64 # Library for encoding and decoding data in base64 format | |
| def encode_image(image_path: str) -> str: | |
| """ | |
| Encode an image file to a base64 string. | |
| Args: | |
| image_path (str): The file path of the image to be encoded. | |
| Returns: | |
| str: The base64-encoded string representation of the image. | |
| """ | |
| # Open the image file in binary read mode | |
| with open(image_path, "rb") as image_file: | |
| # Read the image content, encode it to base64, and decode it to a UTF-8 string | |
| return base64.b64encode(image_file.read()).decode('utf-8') | |