## Utility Functions # Score to colors function score_to_color(score) if score ≤ 0.5 # Interpolate from blue (#0000FF) to gray (#888888) t = score / 0.5 r = round(Int, (1 - t) * 0 + t * 136) g = round(Int, (1 - t) * 0 + t * 136) b = round(Int, (1 - t) * 255 + t * 136) else # Interpolate from gray (#888888) to red (#FF0000) t = (score - 0.5) / 0.5 r = round(Int, (1 - t) * 136 + t * 255) g = round(Int, (1 - t) * 136 + t * 0) b = round(Int, (1 - t) * 136 + t * 0) end return "rgb($r,$g,$b)" end # Creates a paragraph with colored text based on scores from a dataframe function scored_text_paragraph(df::DataFrame) fragments = String[] for row in eachrow(df) color = score_to_color(row[:score]) text = row[:text] push!(fragments, """$text""") end html = "
" * join(fragments, " ") * "
" return HTML(html) end df = DataFrame(score = [0.1, 0.3, 0.6, 0.9], text = ["This", "is", "a", "test."]) scored_text_paragraph(df)