' + text + '
' + # t1 = time.time() + # print(f"Modifier: {(t1-t0):.3f} s") + # About 50 ms return text -# Green-yellow-red color scale + def probability_color_scale(prob): + ''' + Green-yellow-red color scale + ''' + rv = 0 gv = 0 if prob <= 0.5: rv = 'ff' - gv = hex(int(255*prob*2))[2:] + gv = hex(int(255 * prob * 2))[2:] if len(gv) < 2: - gv = '0'*(2 - len(gv)) + gv + gv = '0' * (2 - len(gv)) + gv else: - rv = hex(int(255 - 255*(prob - 0.5)*2))[2:] + rv = hex(int(255 - 255 * (prob - 0.5) * 2))[2:] gv = 'ff' if len(rv) < 2: - rv = '0'*(2 - len(rv)) + rv + rv = '0' * (2 - len(rv)) + rv + return rv + gv + '00' -# Red component only, white for 0 perplexity (sorry if you're not in dark mode) + def perplexity_color_scale(ppl): - value = hex(max(int(255.0 - params['ppl_scale']*(float(ppl)-1.0)), 0))[2:] + ''' + Red component only, white for 0 perplexity (sorry if you're not in dark mode) + ''' + value = hex(max(int(255.0 - params['ppl_scale'] * (float(ppl) - 1.0)), 0))[2:] if len(value) < 2: - value = '0'*(2 - len(value)) + value + value = '0' * (2 - len(value)) + value + return 'ff' + value + value -# Green-yellow-red for probability and blue component for perplexity + def probability_perplexity_color_scale(prob, ppl): + ''' + Green-yellow-red for probability and blue component for perplexity + ''' + rv = 0 gv = 0 - bv = hex(min(max(int(params['ppl_scale']*(float(ppl)-1.0)), 0), 255))[2:] + bv = hex(min(max(int(params['ppl_scale'] * (float(ppl) - 1.0)), 0), 255))[2:] if len(bv) < 2: - bv = '0'*(2 - len(bv)) + bv + bv = '0' * (2 - len(bv)) + bv + if prob <= 0.5: rv = 'ff' - gv = hex(int(255*prob*2))[2:] + gv = hex(int(255 * prob * 2))[2:] if len(gv) < 2: - gv = '0'*(2 - len(gv)) + gv + gv = '0' * (2 - len(gv)) + gv else: - rv = hex(int(255 - 255*(prob - 0.5)*2))[2:] + rv = hex(int(255 - 255 * (prob - 0.5) * 2))[2:] gv = 'ff' if len(rv) < 2: - rv = '0'*(2 - len(rv)) + rv + rv = '0' * (2 - len(rv)) + rv + return rv + gv + bv + def add_color_html(token, color): return f'{token}' -""" -# This is still very broken at the moment, needs CSS too but I'm not very good at CSS (and neither is GPT-4 apparently) so I still need to figure that out. -def add_dropdown_html(token, color, top_tokens, top_probs): - html = f'{token}{token} | {prob} |