import gradio as gr LABEL_BAR_FORMAT = '''
{label_name}
{percentage_score}%

 {label_desc}


''' HTML_FORMAT = '''
{heading}
{LABEL_BARS}
''' def format_labels_html(predictions, desc_is_visible = True): html_text = HTML_FORMAT if 'label' in predictions: x, y = len(set(predictions['preds'].keys()).intersection(predictions['label'])), len(predictions['label']) if y == 0: html_text = html_text.replace('{heading}', f'No Gold Labels Found!') else: html_text = html_text.replace('{heading}', f'{x}/{y} Correct in top 5 Predictions !') else: html_text = html_text.replace('{heading}', f'Top {len(predictions["preds"])} Labels Predicted') label_html_text = "" for i, p in enumerate(predictions['preds']): addn = '\n' + LABEL_BAR_FORMAT.replace('{percentage_score}', f'{int(predictions["preds"][p] * 100)}').replace('{label_name}', p) if 'label' in predictions: if p in predictions['label']: # print('True label encountered') addn = addn.replace('{fill_type}','correct_style') else: addn = addn.replace('{fill_type}','incorrect_style') else: addn = addn.replace('{fill_type}','') if 'descs' in predictions: if desc_is_visible: addn = addn.replace('{desc_is_visible}','') else: addn = addn.replace('{desc_is_visible}','display:none;') addn = addn.replace('{label_desc}',predictions['descs'][p]) else: addn = addn.replace('{desc_is_visible}','display:none;') label_html_text+=addn html_text = html_text.replace('{LABEL_BARS}', label_html_text) # print(html_text) return html_text