gradio-pr-bot commited on
Commit
c6f8e89
·
verified ·
1 Parent(s): c982419

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +6 -6
  2. requirements.txt +2 -0
  3. run.py +262 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Dataframe Widths Main
3
- emoji: 🏢
4
  colorFrom: indigo
5
- colorTo: purple
6
  sdk: gradio
7
  sdk_version: 6.12.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_widths_main
4
+ emoji: 🔥
5
  colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 6.12.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@79c577680978adfb5eeaa01944635e14dc67e5f1#subdirectory=client/python
2
+ https://huggingface.co/buckets/gradio/pypi-previews/resolve/79c577680978adfb5eeaa01944635e14dc67e5f1/gradio-6.12.0-py3-none-any.whl
run.py ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ headers = ["Short", "Medium Column", "Long Description", "Also Long"]
4
+
5
+ short_row = ["id-1", "alpha", "small cell", "small cell"]
6
+ long_row = [
7
+ "id-2",
8
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
9
+ (
10
+ "This is a deliberately very long cell value intended to exceed any "
11
+ "reasonable column width so we can see truncation and wrapping behavior "
12
+ "kick in. It keeps going and going and going so that the column must "
13
+ "either truncate with an ellipsis or wrap across multiple lines."
14
+ ),
15
+ "The quick brown fox jumps over the lazy dog several times in a row.",
16
+ ]
17
+ unbreakable_row = [
18
+ "id-3",
19
+ "ok",
20
+ "Supercalifragilisticexpialidocious" * 4,
21
+ "word " * 30,
22
+ ]
23
+
24
+ data = [
25
+ short_row,
26
+ long_row,
27
+ unbreakable_row,
28
+ short_row,
29
+ long_row,
30
+ unbreakable_row,
31
+ short_row,
32
+ long_row,
33
+ unbreakable_row,
34
+ ]
35
+
36
+ with gr.Blocks(title="Dataframe widths & wrapping") as demo:
37
+ gr.Markdown(
38
+ """
39
+ # Dataframe column widths and wrapping
40
+
41
+ Demonstrates how `wrap` and `column_widths` interact. In every case the
42
+ column's max width is capped at 100% of the dataframe's viewport so a
43
+ single cell can never be wider than the scroll area.
44
+ """
45
+ )
46
+
47
+ with gr.Row():
48
+ with gr.Tab("Defaults (no wrap, auto widths)"):
49
+ gr.Markdown(
50
+ "No `wrap`, no `column_widths`. Columns size to the longest cell; "
51
+ "anything longer than the viewport truncates with an ellipsis."
52
+ )
53
+ gr.Dataframe(value=data, headers=headers)
54
+
55
+ with gr.Tab("wrap=True, auto widths"):
56
+ gr.Markdown(
57
+ "`wrap=True` and no `column_widths`. Columns still size to the "
58
+ "longest cell, but content that would exceed the viewport wraps "
59
+ "onto multiple lines instead of truncating."
60
+ )
61
+ gr.Dataframe(value=data, headers=headers, wrap=True)
62
+
63
+ with gr.Tab("Fixed pixel widths"):
64
+ gr.Markdown(
65
+ "`column_widths=['80px', '160px', '240px', '200px']`. Pixel widths "
66
+ "are honored exactly; long content truncates."
67
+ )
68
+ gr.Dataframe(
69
+ value=data,
70
+ headers=headers,
71
+ column_widths=["80px", "160px", "240px", "200px"],
72
+ )
73
+
74
+ with gr.Tab("Fixed pixel widths + wrap"):
75
+ gr.Markdown(
76
+ "Same fixed widths but `wrap=True`. Long content wraps within the "
77
+ "fixed column instead of truncating."
78
+ )
79
+ gr.Dataframe(
80
+ value=data,
81
+ headers=headers,
82
+ column_widths=["80px", "160px", "240px", "200px"],
83
+ wrap=True,
84
+ )
85
+
86
+ with gr.Tab("Percentage widths"):
87
+ gr.Markdown(
88
+ "`column_widths=['10%', '25%', '40%', '25%']`. Percentages resolve "
89
+ "against the dataframe's viewport width, so they re-flow when you "
90
+ "resize the window."
91
+ )
92
+ gr.Dataframe(
93
+ value=data,
94
+ headers=headers,
95
+ column_widths=["10%", "25%", "40%", "25%"],
96
+ )
97
+
98
+ with gr.Tab("Percentage widths + wrap"):
99
+ gr.Markdown("Same percentages, but with `wrap=True`.")
100
+ gr.Dataframe(
101
+ value=data,
102
+ headers=headers,
103
+ column_widths=["10%", "25%", "40%", "25%"],
104
+ wrap=True,
105
+ )
106
+
107
+ with gr.Tab("Mixed widths (px / % / int)"):
108
+ gr.Markdown(
109
+ "`column_widths=[120, '20%', 'auto', '30%']`. Integers are treated "
110
+ "as pixels; `'auto'` falls back to content-based sizing (capped at "
111
+ "the viewport)."
112
+ )
113
+ gr.Dataframe(
114
+ value=data,
115
+ headers=headers,
116
+ column_widths=[120, "20%", "auto", "30%"],
117
+ )
118
+
119
+ with gr.Tab("max_chars with wide data"):
120
+ gr.Markdown(
121
+ "`max_chars=20` truncates cell text to 20 characters with an "
122
+ "ellipsis. The column is sized to the rendered (truncated) text "
123
+ "rather than the full underlying value, so there's no wasted "
124
+ "horizontal space."
125
+ )
126
+ gr.Dataframe(
127
+ value=data,
128
+ headers=headers,
129
+ max_chars=20,
130
+ )
131
+
132
+ with gr.Tab("max_chars + fixed widths + wrap"):
133
+ gr.Markdown(
134
+ "`max_chars=15`, explicit pixel widths, and `wrap=True`. Text is "
135
+ "first truncated by character count, then wrapped to fit the "
136
+ "column."
137
+ )
138
+ gr.Dataframe(
139
+ value=data,
140
+ headers=headers,
141
+ max_chars=15,
142
+ column_widths=["80px", "160px", "200px", "200px"],
143
+ wrap=True,
144
+ )
145
+
146
+ with gr.Row():
147
+ with gr.Tab("Defaults (no wrap, auto widths)"):
148
+ gr.Markdown(
149
+ "No `wrap`, no `column_widths`. Columns size to the longest cell; "
150
+ "anything longer than the viewport truncates with an ellipsis."
151
+ )
152
+ gr.Dataframe(
153
+ value=data,
154
+ headers=headers,
155
+ interactive=True,
156
+ )
157
+
158
+ with gr.Tab("wrap=True, auto widths"):
159
+ gr.Markdown(
160
+ "`wrap=True` and no `column_widths`. Columns still size to the "
161
+ "longest cell, but content that would exceed the viewport wraps "
162
+ "onto multiple lines instead of truncating."
163
+ )
164
+ gr.Dataframe(
165
+ value=data,
166
+ headers=headers,
167
+ wrap=True,
168
+ interactive=True,
169
+ )
170
+
171
+ with gr.Tab("Fixed pixel widths"):
172
+ gr.Markdown(
173
+ "`column_widths=['80px', '160px', '240px', '200px']`. Pixel widths "
174
+ "are honored exactly; long content truncates."
175
+ )
176
+ gr.Dataframe(
177
+ interactive=True,
178
+ value=data,
179
+ headers=headers,
180
+ column_widths=["80px", "160px", "240px", "200px"],
181
+ )
182
+
183
+ with gr.Tab("Fixed pixel widths + wrap"):
184
+ gr.Markdown(
185
+ "Same fixed widths but `wrap=True`. Long content wraps within the "
186
+ "fixed column instead of truncating."
187
+ )
188
+ gr.Dataframe(
189
+ interactive=True,
190
+ value=data,
191
+ headers=headers,
192
+ column_widths=["80px", "160px", "240px", "200px"],
193
+ wrap=True,
194
+ )
195
+
196
+ with gr.Tab("Percentage widths"):
197
+ gr.Markdown(
198
+ "`column_widths=['10%', '25%', '40%', '25%']`. Percentages resolve "
199
+ "against the dataframe's viewport width, so they re-flow when you "
200
+ "resize the window."
201
+ )
202
+ gr.Dataframe(
203
+ interactive=True,
204
+ value=data,
205
+ headers=headers,
206
+ column_widths=["10%", "25%", "40%", "25%"],
207
+ )
208
+
209
+ with gr.Tab("Percentage widths + wrap"):
210
+ gr.Markdown("Same percentages, but with `wrap=True`.")
211
+ gr.Dataframe(
212
+ value=data,
213
+ interactive=True,
214
+ headers=headers,
215
+ column_widths=["10%", "25%", "40%", "25%"],
216
+ wrap=True,
217
+ )
218
+
219
+ with gr.Tab("Mixed widths (px / % / int)"):
220
+ gr.Markdown(
221
+ "`column_widths=[120, '20%', 'auto', '30%']`. Integers are treated "
222
+ "as pixels; `'auto'` falls back to content-based sizing (capped at "
223
+ "the viewport)."
224
+ )
225
+ gr.Dataframe(
226
+ value=data,
227
+ interactive=True,
228
+ headers=headers,
229
+ column_widths=[120, "20%", "auto", "30%"],
230
+ )
231
+
232
+ with gr.Tab("max_chars with wide data"):
233
+ gr.Markdown(
234
+ "`max_chars=20` truncates cell text to 20 characters with an "
235
+ "ellipsis. The column is sized to the rendered (truncated) text "
236
+ "rather than the full underlying value, so there's no wasted "
237
+ "horizontal space."
238
+ )
239
+ gr.Dataframe(
240
+ interactive=True,
241
+ value=data,
242
+ headers=headers,
243
+ max_chars=20,
244
+ )
245
+
246
+ with gr.Tab("max_chars + fixed widths + wrap"):
247
+ gr.Markdown(
248
+ "`max_chars=15`, explicit pixel widths, and `wrap=True`. Text is "
249
+ "first truncated by character count, then wrapped to fit the "
250
+ "column."
251
+ )
252
+ gr.Dataframe(
253
+ interactive=True,
254
+ value=data,
255
+ headers=headers,
256
+ max_chars=15,
257
+ column_widths=["80px", "160px", "200px", "200px"],
258
+ wrap=True,
259
+ )
260
+
261
+ if __name__ == "__main__":
262
+ demo.launch()