# -*- coding: utf-8 -*- # Copyright (c) Alibaba, Inc. and its affiliates. import copy import os from enum import Enum from scepter.modules.utils.file_system import FS class Media(Enum): TEXT = 1 IMAGE = 2 VIDEO = 3 AUDIO = 4 IMAGE_PAIR = 5 VIDEO_PAIR = 6 class HtmlVisualization(object): def __init__(self, allow_annotation=False, slice_size=1000, align='center', width_scale='60%', title='Visualization', height=600, width=None, text_cols=40): self.content_list = [] self.rows_meta = [] self.allow_annotation = allow_annotation self.slice_size = slice_size self.align = align self.width_scale = width_scale self.title = title self.html_start = '' self.html_head = f'{title}' self.height = height if height is not None else '600' self.width = width if width is not None else 'auto' self.text_cols = text_cols if text_cols is not None else 'auto' self.html_style = (''' \n \n '''.replace('{width_scale}', self.width_scale).replace( '{align}', self.align).replace('{pair_height}', f'{self.height}')) self.html_body_script = ''' \n ''' self.html_body = '{BODY}\n' + self.html_body_script + '\n' self.html_end = '' self.html_script = ''' ''' self.label_button = ( '
' + "" + '
') def format_col(self, content='', label='', type=Media.TEXT, show_label=True, cols_span=1): if type == Media.TEXT: ret_str = '"{content}"' sec_ret_str = f'{label}' if show_label else '' elif type == Media.IMAGE: ret_str = f'{label}' if show_label else '' elif type == Media.VIDEO: ret_str = '' sec_ret_str = f'{label}' if show_label else '' elif type == Media.AUDIO: ret_str = f'