freddyaboulton HF staff commited on
Commit
dcda545
1 Parent(s): 7ed5508

Upload folder using huggingface_hub

Browse files
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ FROM python:3.9
3
+
4
+ WORKDIR /code
5
+
6
+ COPY --link --chown=1000 . .
7
+
8
+ RUN mkdir -p /tmp/cache/
9
+ RUN chmod a+rwx -R /tmp/cache/
10
+ ENV TRANSFORMERS_CACHE=/tmp/cache/
11
+
12
+ RUN pip install --no-cache-dir -r requirements.txt
13
+
14
+ ENV PYTHONUNBUFFERED=1 GRADIO_ALLOW_FLAGGING=never GRADIO_NUM_PORTS=1 GRADIO_SERVER_NAME=0.0.0.0 GRADIO_SERVER_PORT=7860 SYSTEM=spaces
15
+
16
+ CMD ["python", "space.py"]
README.md CHANGED
@@ -1,10 +1,10 @@
 
1
  ---
2
- title: Gradio Leaderboard
3
- emoji:
4
- colorFrom: gray
5
- colorTo: blue
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ tags: [gradio-custom-component]
4
+ title: gradio_leaderboard V0.0.1
5
+ colorFrom: blue
6
+ colorTo: yellow
7
  sdk: docker
8
  pinned: false
9
+ license: apache-2.0
10
  ---
 
 
__init__.py ADDED
File without changes
__pycache__/__init__.cpython-311.pyc ADDED
Binary file (170 Bytes). View file
 
__pycache__/app.cpython-311.pyc ADDED
Binary file (2.4 kB). View file
 
__pycache__/config.cpython-311.pyc ADDED
Binary file (1.16 kB). View file
 
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from gradio_leaderboard import Leaderboard
4
+ import config
5
+ from pathlib import Path
6
+ import pandas as pd
7
+
8
+ abs_path = Path(__file__).parent
9
+
10
+ df = pd.read_json(str(abs_path / "leaderboard_data.json"))
11
+
12
+ # Make a model size column
13
+ numeric_interval = pd.IntervalIndex(
14
+ sorted([config.NUMERIC_INTERVALS[s] for s in config.NUMERIC_INTERVALS.keys()])
15
+ )
16
+ params_column = pd.to_numeric(df["#Params (B)"], errors="coerce")
17
+ df["Model Size"] = params_column.apply(lambda x: next(s for s in numeric_interval if x in s))
18
+
19
+
20
+ with gr.Blocks() as demo:
21
+ gr.Markdown("""
22
+ # 🥇 Leaderboard Component
23
+ """)
24
+ Leaderboard(value=df,
25
+ allow_column_select=True,
26
+ on_load_columns=config.ON_LOAD_COLUMNS,
27
+ search_column="model_name_for_query",
28
+ hide_columns=["model_name_for_query", "Model Size"],
29
+ filter_columns=config.FILTER_COLUMNS,
30
+ datatype=config.TYPES,
31
+ column_widths=["2%", "33%"])
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch()
config.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ TYPES = [
4
+ "str",
5
+ "markdown",
6
+ "number",
7
+ "number",
8
+ "number",
9
+ "number",
10
+ "number",
11
+ "number",
12
+ "number",
13
+ "str",
14
+ "str",
15
+ "str",
16
+ "str",
17
+ "bool",
18
+ "str",
19
+ "number",
20
+ "number",
21
+ "bool",
22
+ "str",
23
+ "bool",
24
+ "bool",
25
+ "str",
26
+ ]
27
+
28
+ ON_LOAD_COLUMNS = [
29
+ "T",
30
+ "Model",
31
+ "Average ⬆️",
32
+ "ARC",
33
+ "HellaSwag",
34
+ "MMLU",
35
+ "TruthfulQA",
36
+ "Winogrande",
37
+ "GSM8K"]
38
+
39
+ FILTER_COLUMNS = ["T",
40
+ "Precision",
41
+ "Model Size"]
42
+
43
+
44
+ NUMERIC_INTERVALS = {
45
+ "?": pd.Interval(-1, 0, closed="right"),
46
+ "~1.5": pd.Interval(0, 2, closed="right"),
47
+ "~3": pd.Interval(2, 4, closed="right"),
48
+ "~7": pd.Interval(4, 9, closed="right"),
49
+ "~13": pd.Interval(9, 20, closed="right"),
50
+ "~35": pd.Interval(20, 45, closed="right"),
51
+ "~60": pd.Interval(45, 70, closed="right"),
52
+ "70+": pd.Interval(70, 10000, closed="right"),
53
+ }
css.css ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html {
2
+ font-family: Inter;
3
+ font-size: 16px;
4
+ font-weight: 400;
5
+ line-height: 1.5;
6
+ -webkit-text-size-adjust: 100%;
7
+ background: #fff;
8
+ color: #323232;
9
+ -webkit-font-smoothing: antialiased;
10
+ -moz-osx-font-smoothing: grayscale;
11
+ text-rendering: optimizeLegibility;
12
+ }
13
+
14
+ :root {
15
+ --space: 1;
16
+ --vspace: calc(var(--space) * 1rem);
17
+ --vspace-0: calc(3 * var(--space) * 1rem);
18
+ --vspace-1: calc(2 * var(--space) * 1rem);
19
+ --vspace-2: calc(1.5 * var(--space) * 1rem);
20
+ --vspace-3: calc(0.5 * var(--space) * 1rem);
21
+ }
22
+
23
+ .app {
24
+ max-width: 748px !important;
25
+ }
26
+
27
+ .prose p {
28
+ margin: var(--vspace) 0;
29
+ line-height: var(--vspace * 2);
30
+ font-size: 1rem;
31
+ }
32
+
33
+ code {
34
+ font-family: "Inconsolata", sans-serif;
35
+ font-size: 16px;
36
+ }
37
+
38
+ h1,
39
+ h1 code {
40
+ font-weight: 400;
41
+ line-height: calc(2.5 / var(--space) * var(--vspace));
42
+ }
43
+
44
+ h1 code {
45
+ background: none;
46
+ border: none;
47
+ letter-spacing: 0.05em;
48
+ padding-bottom: 5px;
49
+ position: relative;
50
+ padding: 0;
51
+ }
52
+
53
+ h2 {
54
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
55
+ line-height: 1em;
56
+ }
57
+
58
+ h3,
59
+ h3 code {
60
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
61
+ line-height: 1em;
62
+ }
63
+
64
+ h4,
65
+ h5,
66
+ h6 {
67
+ margin: var(--vspace-3) 0 var(--vspace-3) 0;
68
+ line-height: var(--vspace);
69
+ }
70
+
71
+ .bigtitle,
72
+ h1,
73
+ h1 code {
74
+ font-size: calc(8px * 4.5);
75
+ word-break: break-word;
76
+ }
77
+
78
+ .title,
79
+ h2,
80
+ h2 code {
81
+ font-size: calc(8px * 3.375);
82
+ font-weight: lighter;
83
+ word-break: break-word;
84
+ border: none;
85
+ background: none;
86
+ }
87
+
88
+ .subheading1,
89
+ h3,
90
+ h3 code {
91
+ font-size: calc(8px * 1.8);
92
+ font-weight: 600;
93
+ border: none;
94
+ background: none;
95
+ letter-spacing: 0.1em;
96
+ text-transform: uppercase;
97
+ }
98
+
99
+ h2 code {
100
+ padding: 0;
101
+ position: relative;
102
+ letter-spacing: 0.05em;
103
+ }
104
+
105
+ blockquote {
106
+ font-size: calc(8px * 1.1667);
107
+ font-style: italic;
108
+ line-height: calc(1.1667 * var(--vspace));
109
+ margin: var(--vspace-2) var(--vspace-2);
110
+ }
111
+
112
+ .subheading2,
113
+ h4 {
114
+ font-size: calc(8px * 1.4292);
115
+ text-transform: uppercase;
116
+ font-weight: 600;
117
+ }
118
+
119
+ .subheading3,
120
+ h5 {
121
+ font-size: calc(8px * 1.2917);
122
+ line-height: calc(1.2917 * var(--vspace));
123
+
124
+ font-weight: lighter;
125
+ text-transform: uppercase;
126
+ letter-spacing: 0.15em;
127
+ }
128
+
129
+ h6 {
130
+ font-size: calc(8px * 1.1667);
131
+ font-size: 1.1667em;
132
+ font-weight: normal;
133
+ font-style: italic;
134
+ font-family: "le-monde-livre-classic-byol", serif !important;
135
+ letter-spacing: 0px !important;
136
+ }
137
+
138
+ #start .md > *:first-child {
139
+ margin-top: 0;
140
+ }
141
+
142
+ h2 + h3 {
143
+ margin-top: 0;
144
+ }
145
+
146
+ .md hr {
147
+ border: none;
148
+ border-top: 1px solid var(--block-border-color);
149
+ margin: var(--vspace-2) 0 var(--vspace-2) 0;
150
+ }
151
+ .prose ul {
152
+ margin: var(--vspace-2) 0 var(--vspace-1) 0;
153
+ }
154
+
155
+ .gap {
156
+ gap: 0;
157
+ }
leaderboard_data.json ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio_leaderboard==0.0.1
space.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'Leaderboard': {'description': 'This component displays a table of value spreadsheet-like component. Can be used to display data as an output component, or as an input to collect data from the user.', 'members': {'__init__': {'value': {'type': 'pd.DataFrame | None', 'default': 'None', 'description': 'Default value to display in the DataFrame. If a Styler is provided, it will be used to set the displayed value in the DataFrame (e.g. to set precision of numbers) if the `interactive` is False. If a Callable function is provided, the function will be called whenever the app loads to set the initial value of the component.'}, 'datatype': {'type': 'str | list[str]', 'default': '"str"', 'description': 'Datatype of values in sheet. Can be provided per column as a list of strings, or for the entire sheet as a single string. Valid datatypes are "str", "number", "bool", "date", and "markdown".'}, 'search_column': {'type': 'str | None', 'default': 'None', 'description': None}, 'filter_columns': {'type': 'list[str] | None', 'default': 'None', 'description': None}, 'hide_columns': {'type': 'list[str] | None', 'default': 'None', 'description': None}, 'allow_column_select': {'type': 'bool', 'default': 'True', 'description': None}, 'on_load_columns': {'type': 'list[str] | None', 'default': 'None', 'description': None}, 'latex_delimiters': {'type': 'list[dict[str, str | bool]] | None', 'default': 'None', 'description': 'A list of dicts of the form {"left": open delimiter (str), "right": close delimiter (str), "display": whether to display in newline (bool)} that will be used to render LaTeX expressions. If not provided, `latex_delimiters` is set to `[{ "left": "$$", "right": "$$", "display": True }]`, so only expressions enclosed in $$ delimiters will be rendered as LaTeX, and in a new line. Pass in an empty list to disable LaTeX rendering. For more information, see the [KaTeX documentation](https://katex.org/docs/autorender.html). Only applies to columns whose datatype is "markdown".'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.'}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': 'if True, will display label.'}, 'every': {'type': 'float | None', 'default': 'None', 'description': "If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute."}, 'height': {'type': 'int', 'default': '500', 'description': 'The maximum height of the dataframe, specified in pixels if a number is passed, or in CSS units if a string is passed. If more rows are created than can fit in the height, a scrollbar will appear.'}, 'scale': {'type': 'int | None', 'default': 'None', 'description': 'relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.'}, 'min_width': {'type': 'int', 'default': '160', 'description': 'minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.'}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': 'if True, will allow users to edit the dataframe; if False, can only be used to display data. If not provided, this is inferred based on whether the component is used as an input or output.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': 'If False, component will be hidden.'}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': 'An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': 'An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'render': {'type': 'bool', 'default': 'True', 'description': 'If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.'}, 'wrap': {'type': 'bool', 'default': 'False', 'description': 'If True, the text in table cells will wrap when appropriate. If False and the `column_width` parameter is not set, the column widths will expand based on the cell contents and the table may need to be horizontally scrolled. If `column_width` is set, then any overflow text will be hidden.'}, 'line_breaks': {'type': 'bool', 'default': 'True', 'description': 'If True (default), will enable Github-flavored Markdown line breaks in chatbot messages. If False, single new lines will be ignored. Only applies for columns of type "markdown."'}, 'column_widths': {'type': 'list[str | int] | None', 'default': 'None', 'description': 'An optional list representing the width of each column. The elements of the list should be in the format "100px" (ints are also accepted and converted to pixel values) or "10%". If not provided, the column widths will be automatically determined based on the content of the cells. Setting this parameter will cause the browser to try to fit the table within the page width.'}}, 'postprocess': {'value': {'type': 'pd.DataFrame', 'description': "Expects data any of these formats: `pandas.DataFrame`, `pandas.Styler`, `numpy.array`, `polars.DataFrame`, `list[list]`, `list`, or a `dict` with keys 'data' (and optionally 'headers'), or `str` path to a csv, which is rendered as the spreadsheet."}}, 'preprocess': {'return': {'type': 'pd.DataFrame', 'description': 'Passes the uploaded spreadsheet data as a `pandas.DataFrame`, `numpy.array`, `polars.DataFrame`, or native 2D Python `list[list]` depending on `type`'}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the Leaderboard changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'input': {'type': None, 'default': None, 'description': 'This listener is triggered when the user changes the value of the Leaderboard.'}, 'select': {'type': None, 'default': None, 'description': 'Event listener for when the user selects or deselects the Leaderboard. Uses event data gradio.SelectData to carry `value` referring to the label of the Leaderboard, and `selected` to refer to state of the Leaderboard. See EventData documentation on how to use this event data'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Leaderboard': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_leaderboard`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
25
+ </div>
26
+
27
+ Super fast , batteries included Leaderboard component ⚡️
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_leaderboard
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+
42
+ import gradio as gr
43
+ from gradio_leaderboard import Leaderboard
44
+ import config
45
+ from pathlib import Path
46
+ import pandas as pd
47
+
48
+ abs_path = Path(__file__).parent
49
+
50
+ df = pd.read_json(str(abs_path / "leaderboard_data.json"))
51
+
52
+ # Make a model size column
53
+ numeric_interval = pd.IntervalIndex(
54
+ sorted([config.NUMERIC_INTERVALS[s] for s in config.NUMERIC_INTERVALS.keys()])
55
+ )
56
+ params_column = pd.to_numeric(df["#Params (B)"], errors="coerce")
57
+ df["Model Size"] = params_column.apply(lambda x: next(s for s in numeric_interval if x in s))
58
+
59
+
60
+ with gr.Blocks() as demo:
61
+ gr.Markdown(\"\"\"
62
+ # 🥇 Leaderboard Component
63
+ \"\"\")
64
+ Leaderboard(value=df,
65
+ allow_column_select=True,
66
+ on_load_columns=config.ON_LOAD_COLUMNS,
67
+ search_column="model_name_for_query",
68
+ hide_columns=["model_name_for_query", "Model Size"],
69
+ filter_columns=config.FILTER_COLUMNS,
70
+ datatype=config.TYPES,
71
+ column_widths=["2%", "33%"])
72
+
73
+ if __name__ == "__main__":
74
+ demo.launch()
75
+
76
+ ```
77
+ """, elem_classes=["md-custom"], header_links=True)
78
+
79
+
80
+ gr.Markdown("""
81
+ ## `Leaderboard`
82
+
83
+ ### Initialization
84
+ """, elem_classes=["md-custom"], header_links=True)
85
+
86
+ gr.ParamViewer(value=_docs["Leaderboard"]["members"]["__init__"], linkify=[])
87
+
88
+
89
+ gr.Markdown("### Events")
90
+ gr.ParamViewer(value=_docs["Leaderboard"]["events"], linkify=['Event'])
91
+
92
+
93
+
94
+
95
+ gr.Markdown("""
96
+
97
+ ### User function
98
+
99
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
100
+
101
+ - When used as an Input, the component only impacts the input signature of the user function.
102
+ - When used as an output, the component only impacts the return signature of the user function.
103
+
104
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
105
+
106
+ - **As input:** Is passed, passes the uploaded spreadsheet data as a `pandas.DataFrame`, `numpy.array`, `polars.DataFrame`, or native 2D Python `list[list]` depending on `type`.
107
+ - **As output:** Should return, expects data any of these formats: `pandas.DataFrame`, `pandas.Styler`, `numpy.array`, `polars.DataFrame`, `list[list]`, `list`, or a `dict` with keys 'data' (and optionally 'headers'), or `str` path to a csv, which is rendered as the spreadsheet.
108
+
109
+ ```python
110
+ def predict(
111
+ value: pd.DataFrame
112
+ ) -> pd.DataFrame:
113
+ return value
114
+ ```
115
+ """, elem_classes=["md-custom", "Leaderboard-user-fn"], header_links=True)
116
+
117
+
118
+
119
+
120
+ demo.load(None, js=r"""function() {
121
+ const refs = {};
122
+ const user_fn_refs = {
123
+ Leaderboard: [], };
124
+ requestAnimationFrame(() => {
125
+
126
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
127
+ if (refs.length > 0) {
128
+ const el = document.querySelector(`.${key}-user-fn`);
129
+ if (!el) return;
130
+ refs.forEach(ref => {
131
+ el.innerHTML = el.innerHTML.replace(
132
+ new RegExp("\\b"+ref+"\\b", "g"),
133
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
134
+ );
135
+ })
136
+ }
137
+ })
138
+
139
+ Object.entries(refs).forEach(([key, refs]) => {
140
+ if (refs.length > 0) {
141
+ const el = document.querySelector(`.${key}`);
142
+ if (!el) return;
143
+ refs.forEach(ref => {
144
+ el.innerHTML = el.innerHTML.replace(
145
+ new RegExp("\\b"+ref+"\\b", "g"),
146
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
147
+ );
148
+ })
149
+ }
150
+ })
151
+ })
152
+ }
153
+
154
+ """)
155
+
156
+ demo.launch()