freddyaboulton HF staff commited on
Commit
da37c55
·
verified ·
1 Parent(s): 85e9da8

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +7 -7
  2. requirements.txt +2 -0
  3. run.ipynb +1 -0
  4. run.py +43 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Dataframe Custom Styling Main
3
- emoji: 🐨
4
- colorFrom: red
5
- colorTo: green
6
  sdk: gradio
7
  sdk_version: 5.18.0
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: dataframe_custom_styling_main
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 5.18.0
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio-client @ git+https://github.com/gradio-app/gradio@b43200d7df92e40285c1e5fb1a2f010278fce5d2#subdirectory=client/python
2
+ https://gradio-pypi-previews.s3.amazonaws.com/b43200d7df92e40285c1e5fb1a2f010278fce5d2/gradio-5.18.0-py3-none-any.whl
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"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}
run.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ data = [
4
+ ["DeepSeek Coder", 79.3],
5
+ ["Llama 3.3", 68.9],
6
+ ["Qwen 2.5", 61.9],
7
+ ["Gemma 2", 59.5],
8
+ ["GPT 2", 18.3],
9
+ ]
10
+
11
+ headers = ["Model", "% Correct (LeetCode Hard)"]
12
+
13
+ def get_styling(values):
14
+ return [["", f"background: linear-gradient(90deg, rgba(220, 242, 220) {row[1]}%, transparent {row[1]}%)"] for row in values]
15
+
16
+ def get_display_value(values):
17
+ display_values = []
18
+ medals = ["🥇", "🥈", "🥉"]
19
+ for i, row in enumerate(values):
20
+ if i < 3:
21
+ display_values.append([f"{medals[i]} {row[0]}", row[1]])
22
+ else:
23
+ display_values.append([row[0], row[1]])
24
+ return display_values
25
+
26
+ styling = get_styling(data)
27
+ display_value = get_display_value(data)
28
+
29
+
30
+ value = {
31
+ "data": data,
32
+ "headers": headers,
33
+ "metadata": {
34
+ "styling": styling,
35
+ "display_value": display_value,
36
+ },
37
+ }
38
+
39
+ with gr.Blocks() as demo:
40
+ gr.Dataframe(value, show_search="search")
41
+
42
+ if __name__ == "__main__":
43
+ demo.launch()