{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: dataframe_custom_styling"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "data = [\n", " [\"DeepSeek Coder\", 79.3],\n", " [\"Llama 3.3\", 68.9],\n", " [\"Qwen 2.5\", 61.9],\n", " [\"Gemma 2\", 59.5],\n", " [\"GPT 2\", 18.3],\n", "]\n", "\n", "headers = [\"Model\", \"% Correct (LeetCode Hard)\"]\n", "\n", "def get_styling(values):\n", " return [[\"\", f\"background: linear-gradient(90deg, rgba(220, 242, 220) {row[1]}%, transparent {row[1]}%)\"] for row in values]\n", "\n", "def get_display_value(values):\n", " display_values = []\n", " medals = [\"\ud83e\udd47\", \"\ud83e\udd48\", \"\ud83e\udd49\"]\n", " for i, row in enumerate(values):\n", " if i < 3:\n", " display_values.append([f\"{medals[i]} {row[0]}\", row[1]])\n", " else:\n", " display_values.append([row[0], row[1]])\n", " return display_values\n", "\n", "styling = get_styling(data)\n", "display_value = get_display_value(data)\n", "\n", "\n", "value = {\n", " \"data\": data,\n", " \"headers\": headers,\n", " \"metadata\": {\n", " \"styling\": styling,\n", " \"display_value\": display_value,\n", " },\n", "}\n", "\n", "with gr.Blocks() as demo:\n", " gr.Dataframe(value, show_search=\"search\")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}