Spaces:
Sleeping
Sleeping
import pandas as pd | |
import gradio as gr | |
# Sample DataFrame | |
data = { | |
"Name": [ | |
"Alice", | |
"Bob", | |
"Charlie", | |
"David", | |
"Eva", | |
"Charlize", | |
"Barbara", | |
"Hans", | |
"Sandra", | |
"Erik", | |
], | |
"Age": [25, 30, 35, 40, 45, 29, 80, 95, 10, 25], | |
"Score": [88, 92, 87, 94, 90, 88, 92, 87, 94, 90], | |
"likes_cheese": [ | |
"no", | |
"yes", | |
"no_opinion", | |
"yes", | |
"no", | |
"no", | |
"yes", | |
"no_opinion", | |
"yes", | |
"no", | |
], | |
} | |
df = pd.DataFrame(data) | |
# Define colors for the different values in the "likes_cheese" column | |
colors = { | |
"yes": "lightgreen", | |
"no": "lightcoral", | |
"no_opinion": "#eee", | |
} | |
def highlight_row(s): | |
color = colors[s["likes_cheese"]] | |
# we set the text color to dark gray here so that it is readable | |
return ["color: #333; background-color: %s" % color for _ in s] | |
styler = df.style.apply(highlight_row, axis="columns") | |
with gr.Blocks() as demo: | |
gr.Dataframe(styler) | |
if __name__ == "__main__": | |
demo.launch() | |