stringalign.visualize#
- class stringalign.visualize.HtmlString[source]#
A string that represents HTML content. It has the _repr_html_ method for rendering in Jupyter notebooks.
- stringalign.visualize.base64_encode_image(image: PIL.Image.Image) bytes[source]#
Convert a PIL image into a base64-encoded JPEG image.
Paramters#
- image
Image to serialize
- returns:
Base64 encoded JPEG image
- rtype:
bytes
- stringalign.visualize.compress_css(css: str) str[source]#
Simple compression of css that turns all whitespace into a single space.
This will remove newlines, tabs, and multiple spaces, (somewhat similar to minification, but not as thorough)
- Parameters:
css – CSS-content to compress
- Returns:
compressed_css – The compressed CSS.
- Return type:
- stringalign.visualize.create_alignment_html(alignment: AlignmentTuple, reference_label: str = 'Reference:', predicted_label: str = 'Predicted:', stylesheet: str | None = None, space_alignment_ops: bool = False) HtmlString[source]#
Create an HTML representation of the alignment with embedded CSS styles.
See Visualizing alignments for an example.
Arguments:#
- alignment:
The alignment data to visualize.
- reference_label:
The label for the reference text.
- predicted_label:
The label for the predicted text.
- stylesheet:
Optional CSS stylesheet to apply. If None, a default stylesheet is used. For no styling, pass an empty string.
- space_alignment_ops
If this is True, then there will be a small space between each alignment operation.
Returns:#
- HtmlString:
An HTML string representing the alignment with embedded styles.
- stringalign.visualize.create_alignment_stylesheet() str[source]#
Get the css used for styling the alignment operation visualisation.
- Returns:
String containing the alignment operation visualisation CSS.
- Return type:
- stringalign.visualize.create_html_image(image: PIL.Image.Image | Path | str, width=500, alt=None) HtmlString[source]#
Convert a PIL image into a HTML image tag with a base64-encoded JPEG image to e.g. embed in Jupyter notebooks.
- Parameters:
image – The image to convert into an HTML image tag with base64 encoded data.
width – The width of the image tag
alt (optional) – The alt text of the image tag
- Returns:
A string with an image tag containing the base64-encoded image.
- Return type: