gsarti commited on
Commit
557e3fe
·
1 Parent(s): 4a8b5ec

Revert changes

Browse files
Files changed (6) hide show
  1. app.py +364 -83
  2. css.css +0 -157
  3. space.py +0 -257
  4. src/.gitignore +1 -0
  5. src/README.md +25 -500
  6. src/pyproject.toml +2 -2
app.py CHANGED
@@ -1,5 +1,182 @@
 
 
1
  import gradio as gr
2
- from ..backend.gradio_highlightedtextbox import HighlightedTextbox
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
 
5
  def convert_tagged_text_to_highlighted_text(
@@ -38,98 +215,202 @@ def show_info(
38
 
39
  initial_text = "It is not something to be ashamed of: it is no different from the <a>personal fears</a> and <b>dislikes</b> of other things that <c>manny peopl</c> have."
40
 
41
- with gr.Blocks() as demo:
42
- gr.Markdown("### Parameters to control the highlighted textbox:")
43
- with gr.Row():
44
- tag_id = gr.Dropdown(
45
- choices=["Error A", "Error B", "Error C"],
46
- value=["Error A", "Error B", "Error C"],
47
- multiselect=True,
48
- allow_custom_value=True,
49
- label="Tag ID",
50
- show_label=True,
51
- info="Insert one or more tag IDs to use in the highlighted textbox.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  )
53
- tag_open = gr.Dropdown(
54
- choices=["<a>", "<b>", "<c>"],
55
- value=["<a>", "<b>", "<c>"],
56
- multiselect=True,
57
- allow_custom_value=True,
58
- label="Tag open",
59
- show_label=True,
60
- info="Insert one or more tags to mark the beginning of a highlighted section.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  )
62
- tag_close = gr.Dropdown(
63
- choices=["</a>", "</b>", "</c>"],
64
- value=["</a>", "</b>", "</c>"],
65
- multiselect=True,
66
- allow_custom_value=True,
67
- label="Tag close",
68
- show_label=True,
69
- info="Insert one or more tags to mark the end of a highlighted section.",
70
  )
71
- gr.Markdown(
72
- """
73
- ### Example:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
- The following text is tagged using the parameters above to mark spans that will be highlighted.
 
 
 
 
76
 
77
- Both the tagged text and the highlighted text are editable, so you can see how the changes in one affect the other.
 
 
78
 
79
- Highlights will disappear if the highlighted text is edited. Modals will appear upon focus, change, and blur events on the highlighted text.
80
- """
81
- )
82
- with gr.Row():
83
- tagged = gr.Textbox(
84
- initial_text,
85
- interactive=True,
86
- label="Tagged text",
87
- show_label=True,
88
- info="Tagged text using the format above to mark spans that will be highlighted.",
89
  )
90
- high = HighlightedTextbox(
91
- convert_tagged_text_to_highlighted_text(
92
- tagged.value, tag_id.value, tag_open.value, tag_close.value
93
- ),
94
- interactive=True,
95
- label="Highlighted text",
96
- info="Textbox containing editable text with custom highlights.",
97
- show_legend=True,
98
- show_label=True,
99
- legend_label="Legend:",
100
- show_legend_label=True,
101
- show_remove_tags_button=True,
102
- show_copy_button=False,
103
- color_map={"Error A": "blue", "Error B": "red", "Error C": "green"},
104
  )
105
 
106
- # Functions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
- tagged.input(
109
- fn=convert_tagged_text_to_highlighted_text,
110
- inputs=[tagged, tag_id, tag_open, tag_close],
111
- outputs=high,
112
- )
113
- high.input(
114
- fn=convert_highlighted_text_to_tagged_text,
115
- inputs=[high, tag_id, tag_open, tag_close],
116
- outputs=tagged,
117
- )
118
- high.focus(
119
- fn=show_info,
120
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Focus")],
121
- outputs=None,
122
- )
123
- high.blur(
124
- fn=show_info,
125
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Blur")],
126
- outputs=None,
127
- )
128
- high.clear(
129
- fn=show_info,
130
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Remove tags")],
131
- outputs=None,
132
- )
133
 
134
  if __name__ == "__main__":
135
  demo.launch()
 
1
+ import os
2
+
3
  import gradio as gr
4
+
5
+ from gradio_highlightedtextbox import HighlightedTextbox
6
+
7
+ _docs = {
8
+ "HighlightedTextbox": {
9
+ "description": 'Creates a textarea for user to enter string input or display string output where some\nelements are highlighted.\n (1) "text" whose value is the complete text, and\n (2) "highlights", which is a list of dictionaries, each of which have the keys:\n "highlight_type" (consisting of the highlight label),\n "start" (the character index where the label starts), and\n "end" (the character index where the label ends).\n Highlights should not overlap.',
10
+ "members": {
11
+ "__init__": {
12
+ "value": {
13
+ "type": "str | Callable | None",
14
+ "default": '""',
15
+ "description": "default text to provide in textbox. If callable, the function will be called whenever the app loads to set the initial value of the component.",
16
+ },
17
+ "color_map": {
18
+ "type": "dict[str, str] | None",
19
+ "default": "None",
20
+ "description": "dictionary mapping labels to colors.",
21
+ },
22
+ "show_legend": {
23
+ "type": "bool",
24
+ "default": "False",
25
+ "description": "if True, will display legend.",
26
+ },
27
+ "show_legend_label": {
28
+ "type": "bool",
29
+ "default": "False",
30
+ "description": "if True, will display legend label.",
31
+ },
32
+ "legend_label": {
33
+ "type": "str",
34
+ "default": '""',
35
+ "description": "label to display above legend.",
36
+ },
37
+ "combine_adjacent": {
38
+ "type": "bool",
39
+ "default": "False",
40
+ "description": "if True, will combine adjacent spans with the same label.",
41
+ },
42
+ "adjacent_separator": {
43
+ "type": "str",
44
+ "default": '""',
45
+ "description": "separator to use when combining adjacent spans.",
46
+ },
47
+ "label": {
48
+ "type": "str | None",
49
+ "default": "None",
50
+ "description": "component name in interface.",
51
+ },
52
+ "info": {"type": "str | None", "default": "None", "description": None},
53
+ "every": {
54
+ "type": "float | None",
55
+ "default": "None",
56
+ "description": "If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.",
57
+ },
58
+ "show_label": {
59
+ "type": "bool | None",
60
+ "default": "None",
61
+ "description": "if True, will display label.",
62
+ },
63
+ "container": {
64
+ "type": "bool",
65
+ "default": "True",
66
+ "description": "If True, will place the component in a container - providing some extra padding around the border.",
67
+ },
68
+ "scale": {
69
+ "type": "int | None",
70
+ "default": "None",
71
+ "description": "relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.",
72
+ },
73
+ "min_width": {
74
+ "type": "int",
75
+ "default": "160",
76
+ "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.",
77
+ },
78
+ "visible": {
79
+ "type": "bool",
80
+ "default": "True",
81
+ "description": "If False, component will be hidden.",
82
+ },
83
+ "elem_id": {
84
+ "type": "str | None",
85
+ "default": "None",
86
+ "description": "An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.",
87
+ },
88
+ "autofocus": {"type": "bool", "default": "False", "description": None},
89
+ "autoscroll": {
90
+ "type": "bool",
91
+ "default": "True",
92
+ "description": "If True, will automatically scroll to the bottom of the textbox when the value changes, unless the user scrolls up. If False, will not scroll to the bottom of the textbox when the value changes.",
93
+ },
94
+ "interactive": {
95
+ "type": "bool",
96
+ "default": "True",
97
+ "description": "if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.",
98
+ },
99
+ "elem_classes": {
100
+ "type": "list[str] | str | None",
101
+ "default": "None",
102
+ "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.",
103
+ },
104
+ "render": {
105
+ "type": "bool",
106
+ "default": "True",
107
+ "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.",
108
+ },
109
+ "show_copy_button": {
110
+ "type": "bool",
111
+ "default": "False",
112
+ "description": "If True, includes a copy button to copy the text in the textbox. Only applies if show_label is True.",
113
+ },
114
+ "show_remove_tags_button": {
115
+ "type": "bool",
116
+ "default": "False",
117
+ "description": "If True, includes a remove tags button to remove all highlights from the text.",
118
+ },
119
+ },
120
+ "postprocess": {
121
+ "y": {
122
+ "type": "list[tuple[str, str | None]] | dict | None",
123
+ "description": 'List of (word, category) tuples, or a dictionary of two keys: "text", and "highlights", which itself is',
124
+ },
125
+ "value": {
126
+ "type": "list[tuple[str, str | None]] | dict | None",
127
+ "description": 'List of (word, category) tuples, or a dictionary of two keys: "text", and "highlights", which itself is',
128
+ },
129
+ },
130
+ "preprocess": {
131
+ "return": {"type": "dict", "description": None},
132
+ "value": None,
133
+ },
134
+ },
135
+ "events": {
136
+ "change": {
137
+ "type": None,
138
+ "default": None,
139
+ "description": "Triggered when the value of the HighlightedTextbox 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.",
140
+ },
141
+ "input": {
142
+ "type": None,
143
+ "default": None,
144
+ "description": "This listener is triggered when the user changes the value of the HighlightedTextbox.",
145
+ },
146
+ "select": {
147
+ "type": None,
148
+ "default": None,
149
+ "description": "Event listener for when the user selects or deselects the HighlightedTextbox. Uses event data gradio.SelectData to carry `value` referring to the label of the HighlightedTextbox, and `selected` to refer to state of the HighlightedTextbox. See EventData documentation on how to use this event data",
150
+ },
151
+ "submit": {
152
+ "type": None,
153
+ "default": None,
154
+ "description": "This listener is triggered when the user presses the Enter key while the HighlightedTextbox is focused.",
155
+ },
156
+ "focus": {
157
+ "type": None,
158
+ "default": None,
159
+ "description": "This listener is triggered when the HighlightedTextbox is focused.",
160
+ },
161
+ "blur": {
162
+ "type": None,
163
+ "default": None,
164
+ "description": "This listener is triggered when the HighlightedTextbox is unfocused/blurred.",
165
+ },
166
+ "clear": {
167
+ "type": None,
168
+ "default": None,
169
+ "description": "This listener is triggered when the HighlightedTextbox is cleared from highlights using the remove_tags button.",
170
+ },
171
+ },
172
+ },
173
+ "__meta__": {
174
+ "additional_interfaces": {},
175
+ "user_fn_refs": {"HighlightedTextbox": []},
176
+ },
177
+ }
178
+
179
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
180
 
181
 
182
  def convert_tagged_text_to_highlighted_text(
 
215
 
216
  initial_text = "It is not something to be ashamed of: it is no different from the <a>personal fears</a> and <b>dislikes</b> of other things that <c>manny peopl</c> have."
217
 
218
+ with gr.Blocks(
219
+ css=abs_path,
220
+ theme=gr.themes.Default(
221
+ font_mono=[
222
+ gr.themes.GoogleFont("Inconsolata"),
223
+ "monospace",
224
+ ],
225
+ ),
226
+ ) as demo:
227
+ with gr.Tab("Demo"):
228
+ gr.Markdown("### Parameters to control the highlighted textbox:")
229
+ with gr.Row():
230
+ tag_id = gr.Dropdown(
231
+ choices=["Error A", "Error B", "Error C"],
232
+ value=["Error A", "Error B", "Error C"],
233
+ multiselect=True,
234
+ allow_custom_value=True,
235
+ label="Tag ID",
236
+ show_label=True,
237
+ info="Insert one or more tag IDs to use in the highlighted textbox.",
238
+ )
239
+ tag_open = gr.Dropdown(
240
+ choices=["<a>", "<b>", "<c>"],
241
+ value=["<a>", "<b>", "<c>"],
242
+ multiselect=True,
243
+ allow_custom_value=True,
244
+ label="Tag open",
245
+ show_label=True,
246
+ info="Insert one or more tags to mark the beginning of a highlighted section.",
247
+ )
248
+ tag_close = gr.Dropdown(
249
+ choices=["</a>", "</b>", "</c>"],
250
+ value=["</a>", "</b>", "</c>"],
251
+ multiselect=True,
252
+ allow_custom_value=True,
253
+ label="Tag close",
254
+ show_label=True,
255
+ info="Insert one or more tags to mark the end of a highlighted section.",
256
+ )
257
+ gr.Markdown(
258
+ """
259
+ ### Example:
260
+
261
+ The following text is tagged using the parameters above to mark spans that will be highlighted.
262
+
263
+ Both the tagged text and the highlighted text are editable, so you can see how the changes in one affect the other.
264
+
265
+ Highlights will disappear if the highlighted text is edited. Modals will appear upon focus, change, and blur events on the highlighted text.
266
+ """
267
  )
268
+ with gr.Row():
269
+ tagged = gr.Textbox(
270
+ initial_text,
271
+ interactive=True,
272
+ label="Tagged text",
273
+ show_label=True,
274
+ info="Tagged text using the format above to mark spans that will be highlighted.",
275
+ )
276
+ high = HighlightedTextbox(
277
+ convert_tagged_text_to_highlighted_text(
278
+ tagged.value, tag_id.value, tag_open.value, tag_close.value
279
+ ),
280
+ interactive=True,
281
+ label="Highlighted text",
282
+ info="Textbox containing editable text with custom highlights.",
283
+ show_legend=True,
284
+ show_label=True,
285
+ legend_label="Legend:",
286
+ show_legend_label=True,
287
+ show_remove_tags_button=True,
288
+ show_copy_button=False,
289
+ )
290
+
291
+ # Functions
292
+
293
+ tagged.input(
294
+ fn=convert_tagged_text_to_highlighted_text,
295
+ inputs=[tagged, tag_id, tag_open, tag_close],
296
+ outputs=high,
297
  )
298
+ high.input(
299
+ fn=convert_highlighted_text_to_tagged_text,
300
+ inputs=[high, tag_id, tag_open, tag_close],
301
+ outputs=tagged,
 
 
 
 
302
  )
303
+ high.focus(
304
+ fn=show_info,
305
+ inputs=[high, tag_id, tag_open, tag_close, gr.State("Focus")],
306
+ outputs=None,
307
+ )
308
+ high.blur(
309
+ fn=show_info,
310
+ inputs=[high, tag_id, tag_open, tag_close, gr.State("Blur")],
311
+ outputs=None,
312
+ )
313
+ high.clear(
314
+ fn=show_info,
315
+ inputs=[high, tag_id, tag_open, tag_close, gr.State("Remove tags")],
316
+ outputs=None,
317
+ )
318
+ with gr.Tab("Docs"):
319
+ gr.Markdown(
320
+ """
321
+ # `gradio_highlightedtextbox`
322
+
323
+ <div style="display: flex; gap: 7px;">
324
+ <a href="https://pypi.org/project/gradio_highlightedtextbox/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_highlightedtextbox"></a> <a href="https://huggingface.co/spaces/gsarti/gradio_highlightedtextbox/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
325
+ </div>
326
 
327
+ Editable Gradio textarea supporting highlighting
328
+ """,
329
+ elem_classes=["md-custom"],
330
+ header_links=True,
331
+ )
332
 
333
+ gr.Markdown(
334
+ """
335
+ ## `HighlightedTextbox`
336
 
337
+ ### Initialization
338
+ """,
339
+ elem_classes=["md-custom"],
340
+ header_links=True,
 
 
 
 
 
 
341
  )
342
+
343
+ gr.ParamViewer(
344
+ value=_docs["HighlightedTextbox"]["members"]["__init__"], linkify=[]
 
 
 
 
 
 
 
 
 
 
 
345
  )
346
 
347
+ gr.Markdown("### Events")
348
+ gr.ParamViewer(value=_docs["HighlightedTextbox"]["events"], linkify=["Event"])
349
+
350
+ gr.Markdown(
351
+ """
352
+
353
+ ### User function
354
+
355
+ 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).
356
+
357
+ - When used as an Input, the component only impacts the input signature of the user function.
358
+ - When used as an output, the component only impacts the return signature of the user function.
359
+
360
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
361
+
362
+ - **As output:** Should return, list of (word, category) tuples, or a dictionary of two keys: "text", and "highlights", which itself is.
363
+
364
+ ```python
365
+ def predict(
366
+ value: dict
367
+ ) -> list[tuple[str, str | None]] | dict | None:
368
+ return value
369
+ ```
370
+ """,
371
+ elem_classes=["md-custom", "HighlightedTextbox-user-fn"],
372
+ header_links=True,
373
+ )
374
+
375
+ demo.load(
376
+ None,
377
+ js=r"""function() {
378
+ const refs = {};
379
+ const user_fn_refs = {
380
+ HighlightedTextbox: [], };
381
+ requestAnimationFrame(() => {
382
+
383
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
384
+ if (refs.length > 0) {
385
+ const el = document.querySelector(`.${key}-user-fn`);
386
+ if (!el) return;
387
+ refs.forEach(ref => {
388
+ el.innerHTML = el.innerHTML.replace(
389
+ new RegExp("\\b"+ref+"\\b", "g"),
390
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
391
+ );
392
+ })
393
+ }
394
+ })
395
+
396
+ Object.entries(refs).forEach(([key, refs]) => {
397
+ if (refs.length > 0) {
398
+ const el = document.querySelector(`.${key}`);
399
+ if (!el) return;
400
+ refs.forEach(ref => {
401
+ el.innerHTML = el.innerHTML.replace(
402
+ new RegExp("\\b"+ref+"\\b", "g"),
403
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
404
+ );
405
+ })
406
+ }
407
+ })
408
+ })
409
+ }
410
+
411
+ """,
412
+ )
413
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
 
415
  if __name__ == "__main__":
416
  demo.launch()
css.css DELETED
@@ -1,157 +0,0 @@
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
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
space.py DELETED
@@ -1,257 +0,0 @@
1
-
2
- import gradio as gr
3
- from app import demo as app
4
- import os
5
-
6
- _docs = {'HighlightedTextbox': {'description': 'Creates a textarea for user to enter string input or display string output where some\nelements are highlighted.\n (1) "text" whose value is the complete text, and\n (2) "highlights", which is a list of dictionaries, each of which have the keys:\n "highlight_type" (consisting of the highlight label),\n "start" (the character index where the label starts), and\n "end" (the character index where the label ends).\n Highlights should not overlap.', 'members': {'__init__': {'value': {'type': 'list[tuple[str, str | None]] | Callable | None', 'default': '""', 'description': 'default text to provide in textbox. If callable, the function will be called whenever the app loads to set the initial value of the component.'}, 'color_map': {'type': 'dict[str, str] | None', 'default': 'None', 'description': 'dictionary mapping labels to colors.'}, 'show_legend': {'type': 'bool', 'default': 'False', 'description': 'if True, will display legend.'}, 'show_legend_label': {'type': 'bool', 'default': 'False', 'description': 'if True, will display legend label.'}, 'legend_label': {'type': 'str', 'default': '""', 'description': 'label to display above legend.'}, 'combine_adjacent': {'type': 'bool', 'default': 'False', 'description': 'if True, will combine adjacent spans with the same label.'}, 'adjacent_separator': {'type': 'str', 'default': '""', 'description': 'separator to use when combining adjacent spans.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'component name in interface.'}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, '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. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute."}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': 'if True, will display label.'}, 'container': {'type': 'bool', 'default': 'True', 'description': 'If True, will place the component in a container - providing some extra padding around the border.'}, 'scale': {'type': 'int | None', 'default': 'None', 'description': 'relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.'}, '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.'}, '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.'}, 'autofocus': {'type': 'bool', 'default': 'False', 'description': None}, 'autoscroll': {'type': 'bool', 'default': 'True', 'description': 'If True, will automatically scroll to the bottom of the textbox when the value changes, unless the user scrolls up. If False, will not scroll to the bottom of the textbox when the value changes.'}, 'interactive': {'type': 'bool', 'default': 'True', 'description': 'if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.'}, '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.'}, 'show_copy_button': {'type': 'bool', 'default': 'False', 'description': 'If True, includes a copy button to copy the text in the textbox. Only applies if show_label is True.'}, 'show_remove_tags_button': {'type': 'bool', 'default': 'False', 'description': 'If True, includes a button to remove all tags from the text.'}}, 'postprocess': {'y': {'type': 'list[tuple[str, str | None]] | dict | None', 'description': 'List of (word, category) tuples, or a dictionary of two keys: "id", and "data", which is a list of (word, category) tuples.'}, 'value': {'type': 'list[tuple[str, str | None]] | dict | None', 'description': 'List of (word, category) tuples, or a dictionary of two keys: "id", and "data", which is a list of (word, category) tuples.'}}, 'preprocess': {'return': {'type': 'dict', 'description': "The preprocessed input data sent to the user's function in the backend."}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the HighlightedTextbox 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 HighlightedTextbox.'}, 'select': {'type': None, 'default': None, 'description': 'Event listener for when the user selects or deselects the HighlightedTextbox. Uses event data gradio.SelectData to carry `value` referring to the label of the HighlightedTextbox, and `selected` to refer to state of the HighlightedTextbox. See EventData documentation on how to use this event data'}, 'submit': {'type': None, 'default': None, 'description': 'This listener is triggered when the user presses the Enter key while the HighlightedTextbox is focused.'}, 'focus': {'type': None, 'default': None, 'description': 'This listener is triggered when the HighlightedTextbox is focused.'}, 'blur': {'type': None, 'default': None, 'description': 'This listener is triggered when the HighlightedTextbox is unfocused/blurred.'}, 'clear': {'type': None, 'default': None, 'description': 'This listener is triggered when the user clears the HighlightedTextbox using the X button for the component.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'HighlightedTextbox': []}}}
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_highlightedtextbox`
22
-
23
- <div style="display: flex; gap: 7px;">
24
- <a href="https://pypi.org/project/gradio_highlightedtextbox/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_highlightedtextbox"></a> <a href="https://huggingface.co/spaces/gsarti/gradio_highlightedtextbox/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
25
- </div>
26
-
27
- Editable Gradio textarea supporting highlighting
28
- """, elem_classes=["md-custom"], header_links=True)
29
- app.render()
30
- gr.Markdown(
31
- """
32
- ## Installation
33
-
34
- ```bash
35
- pip install gradio_highlightedtextbox
36
- ```
37
-
38
- ## Usage
39
-
40
- ```python
41
- import gradio as gr
42
- from ..backend.gradio_highlightedtextbox import HighlightedTextbox
43
-
44
-
45
- def convert_tagged_text_to_highlighted_text(
46
- tagged_text: str,
47
- tag_id: str | list[str],
48
- tag_open: str | list[str],
49
- tag_close: str | list[str],
50
- ) -> list[tuple[str, str | None]]:
51
- return HighlightedTextbox.tagged_text_to_tuples(
52
- tagged_text, tag_id, tag_open, tag_close
53
- )
54
-
55
-
56
- def convert_highlighted_text_to_tagged_text(
57
- highlighted_text: dict[str, str | list[tuple[str, str | None]]],
58
- tag_id: str | list[str],
59
- tag_open: str | list[str],
60
- tag_close: str | list[str],
61
- ) -> str:
62
- return HighlightedTextbox.tuples_to_tagged_text(
63
- highlighted_text["data"], tag_id, tag_open, tag_close
64
- )
65
-
66
-
67
- def show_info(
68
- highlighted_text: dict[str, str | list[tuple[str, str | None]]],
69
- tag_id: str | list[str],
70
- tag_open: str | list[str],
71
- tag_close: str | list[str],
72
- msg: str,
73
- ) -> None:
74
- gr.Info(
75
- f"{msg}: {HighlightedTextbox.tuples_to_tagged_text(highlighted_text['data'], tag_id, tag_open, tag_close)}"
76
- )
77
-
78
-
79
- initial_text = "It is not something to be ashamed of: it is no different from the <a>personal fears</a> and <b>dislikes</b> of other things that <c>manny peopl</c> have."
80
-
81
- with gr.Blocks() as demo:
82
- gr.Markdown("### Parameters to control the highlighted textbox:")
83
- with gr.Row():
84
- tag_id = gr.Dropdown(
85
- choices=["Error A", "Error B", "Error C"],
86
- value=["Error A", "Error B", "Error C"],
87
- multiselect=True,
88
- allow_custom_value=True,
89
- label="Tag ID",
90
- show_label=True,
91
- info="Insert one or more tag IDs to use in the highlighted textbox.",
92
- )
93
- tag_open = gr.Dropdown(
94
- choices=["<a>", "<b>", "<c>"],
95
- value=["<a>", "<b>", "<c>"],
96
- multiselect=True,
97
- allow_custom_value=True,
98
- label="Tag open",
99
- show_label=True,
100
- info="Insert one or more tags to mark the beginning of a highlighted section.",
101
- )
102
- tag_close = gr.Dropdown(
103
- choices=["</a>", "</b>", "</c>"],
104
- value=["</a>", "</b>", "</c>"],
105
- multiselect=True,
106
- allow_custom_value=True,
107
- label="Tag close",
108
- show_label=True,
109
- info="Insert one or more tags to mark the end of a highlighted section.",
110
- )
111
- gr.Markdown(
112
- \"\"\"
113
- ### Example:
114
-
115
- The following text is tagged using the parameters above to mark spans that will be highlighted.
116
-
117
- Both the tagged text and the highlighted text are editable, so you can see how the changes in one affect the other.
118
-
119
- Highlights will disappear if the highlighted text is edited. Modals will appear upon focus, change, and blur events on the highlighted text.
120
- \"\"\"
121
- )
122
- with gr.Row():
123
- tagged = gr.Textbox(
124
- initial_text,
125
- interactive=True,
126
- label="Tagged text",
127
- show_label=True,
128
- info="Tagged text using the format above to mark spans that will be highlighted.",
129
- )
130
- high = HighlightedTextbox(
131
- convert_tagged_text_to_highlighted_text(
132
- tagged.value, tag_id.value, tag_open.value, tag_close.value
133
- ),
134
- interactive=True,
135
- label="Highlighted text",
136
- info="Textbox containing editable text with custom highlights.",
137
- show_legend=True,
138
- show_label=True,
139
- legend_label="Legend:",
140
- show_legend_label=True,
141
- show_remove_tags_button=True,
142
- show_copy_button=False,
143
- color_map={"Error A": "blue", "Error B": "red", "Error C": "green"},
144
- )
145
-
146
- # Functions
147
-
148
- tagged.input(
149
- fn=convert_tagged_text_to_highlighted_text,
150
- inputs=[tagged, tag_id, tag_open, tag_close],
151
- outputs=high,
152
- )
153
- high.input(
154
- fn=convert_highlighted_text_to_tagged_text,
155
- inputs=[high, tag_id, tag_open, tag_close],
156
- outputs=tagged,
157
- )
158
- high.focus(
159
- fn=show_info,
160
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Focus")],
161
- outputs=None,
162
- )
163
- high.blur(
164
- fn=show_info,
165
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Blur")],
166
- outputs=None,
167
- )
168
- high.clear(
169
- fn=show_info,
170
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Remove tags")],
171
- outputs=None,
172
- )
173
-
174
- if __name__ == "__main__":
175
- demo.launch()
176
-
177
- ```
178
- """, elem_classes=["md-custom"], header_links=True)
179
-
180
-
181
- gr.Markdown("""
182
- ## `HighlightedTextbox`
183
-
184
- ### Initialization
185
- """, elem_classes=["md-custom"], header_links=True)
186
-
187
- gr.ParamViewer(value=_docs["HighlightedTextbox"]["members"]["__init__"], linkify=[])
188
-
189
-
190
- gr.Markdown("### Events")
191
- gr.ParamViewer(value=_docs["HighlightedTextbox"]["events"], linkify=['Event'])
192
-
193
-
194
-
195
-
196
- gr.Markdown("""
197
-
198
- ### User function
199
-
200
- 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).
201
-
202
- - When used as an Input, the component only impacts the input signature of the user function.
203
- - When used as an output, the component only impacts the return signature of the user function.
204
-
205
- The code snippet below is accurate in cases where the component is used as both an input and an output.
206
-
207
- - **As input:** Is passed, the preprocessed input data sent to the user's function in the backend.
208
- - **As output:** Should return, list of (word, category) tuples, or a dictionary of two keys: "id", and "data", which is a list of (word, category) tuples.
209
-
210
- ```python
211
- def predict(
212
- value: dict
213
- ) -> list[tuple[str, str | None]] | dict | None:
214
- return value
215
- ```
216
- """, elem_classes=["md-custom", "HighlightedTextbox-user-fn"], header_links=True)
217
-
218
-
219
-
220
-
221
- demo.load(None, js=r"""function() {
222
- const refs = {};
223
- const user_fn_refs = {
224
- HighlightedTextbox: [], };
225
- requestAnimationFrame(() => {
226
-
227
- Object.entries(user_fn_refs).forEach(([key, refs]) => {
228
- if (refs.length > 0) {
229
- const el = document.querySelector(`.${key}-user-fn`);
230
- if (!el) return;
231
- refs.forEach(ref => {
232
- el.innerHTML = el.innerHTML.replace(
233
- new RegExp("\\b"+ref+"\\b", "g"),
234
- `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
235
- );
236
- })
237
- }
238
- })
239
-
240
- Object.entries(refs).forEach(([key, refs]) => {
241
- if (refs.length > 0) {
242
- const el = document.querySelector(`.${key}`);
243
- if (!el) return;
244
- refs.forEach(ref => {
245
- el.innerHTML = el.innerHTML.replace(
246
- new RegExp("\\b"+ref+"\\b", "g"),
247
- `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
248
- );
249
- })
250
- }
251
- })
252
- })
253
- }
254
-
255
- """)
256
-
257
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/.gitignore CHANGED
@@ -6,3 +6,4 @@ __pycache__/
6
  *$py.class
7
  __tmp/*
8
  node_modules
 
 
6
  *$py.class
7
  __tmp/*
8
  node_modules
9
+ *.pyi
src/README.md CHANGED
@@ -1,500 +1,25 @@
1
-
2
- # `gradio_highlightedtextbox`
3
- <a href="https://pypi.org/project/gradio_highlightedtextbox/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_highlightedtextbox"></a> <a href="https://huggingface.co/spaces/gsarti/gradio_highlightedtextbox/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
4
-
5
- Editable Gradio textarea supporting highlighting
6
-
7
- ## Installation
8
-
9
- ```bash
10
- pip install gradio_highlightedtextbox
11
- ```
12
-
13
- ## Usage
14
-
15
- ```python
16
- import gradio as gr
17
- from gradio_highlightedtextbox import HighlightedTextbox
18
-
19
-
20
- def convert_tagged_text_to_highlighted_text(
21
- tagged_text: str,
22
- tag_id: str | list[str],
23
- tag_open: str | list[str],
24
- tag_close: str | list[str],
25
- ) -> list[tuple[str, str | None]]:
26
- return HighlightedTextbox.tagged_text_to_tuples(
27
- tagged_text, tag_id, tag_open, tag_close
28
- )
29
-
30
-
31
- def convert_highlighted_text_to_tagged_text(
32
- highlighted_text: dict[str, str | list[tuple[str, str | None]]],
33
- tag_id: str | list[str],
34
- tag_open: str | list[str],
35
- tag_close: str | list[str],
36
- ) -> str:
37
- return HighlightedTextbox.tuples_to_tagged_text(
38
- highlighted_text["data"], tag_id, tag_open, tag_close
39
- )
40
-
41
-
42
- def show_info(
43
- highlighted_text: dict[str, str | list[tuple[str, str | None]]],
44
- tag_id: str | list[str],
45
- tag_open: str | list[str],
46
- tag_close: str | list[str],
47
- msg: str,
48
- ) -> None:
49
- gr.Info(
50
- f"{msg}: {HighlightedTextbox.tuples_to_tagged_text(highlighted_text['data'], tag_id, tag_open, tag_close)}"
51
- )
52
-
53
-
54
- initial_text = "It is not something to be ashamed of: it is no different from the <a>personal fears</a> and <b>dislikes</b> of other things that <c>manny peopl</c> have."
55
-
56
- with gr.Blocks() as demo:
57
- gr.Markdown("### Parameters to control the highlighted textbox:")
58
- with gr.Row():
59
- tag_id = gr.Dropdown(
60
- choices=["Error A", "Error B", "Error C"],
61
- value=["Error A", "Error B", "Error C"],
62
- multiselect=True,
63
- allow_custom_value=True,
64
- label="Tag ID",
65
- show_label=True,
66
- info="Insert one or more tag IDs to use in the highlighted textbox.",
67
- )
68
- tag_open = gr.Dropdown(
69
- choices=["<a>", "<b>", "<c>"],
70
- value=["<a>", "<b>", "<c>"],
71
- multiselect=True,
72
- allow_custom_value=True,
73
- label="Tag open",
74
- show_label=True,
75
- info="Insert one or more tags to mark the beginning of a highlighted section.",
76
- )
77
- tag_close = gr.Dropdown(
78
- choices=["</a>", "</b>", "</c>"],
79
- value=["</a>", "</b>", "</c>"],
80
- multiselect=True,
81
- allow_custom_value=True,
82
- label="Tag close",
83
- show_label=True,
84
- info="Insert one or more tags to mark the end of a highlighted section.",
85
- )
86
- gr.Markdown(
87
- """
88
- ### Example:
89
-
90
- The following text is tagged using the parameters above to mark spans that will be highlighted.
91
-
92
- Both the tagged text and the highlighted text are editable, so you can see how the changes in one affect the other.
93
-
94
- Highlights will disappear if the highlighted text is edited. Modals will appear upon focus, change, and blur events on the highlighted text.
95
- """
96
- )
97
- with gr.Row():
98
- tagged = gr.Textbox(
99
- initial_text,
100
- interactive=True,
101
- label="Tagged text",
102
- show_label=True,
103
- info="Tagged text using the format above to mark spans that will be highlighted.",
104
- )
105
- high = HighlightedTextbox(
106
- convert_tagged_text_to_highlighted_text(
107
- tagged.value, tag_id.value, tag_open.value, tag_close.value
108
- ),
109
- interactive=True,
110
- label="Highlighted text",
111
- info="Textbox containing editable text with custom highlights.",
112
- show_legend=True,
113
- show_label=True,
114
- legend_label="Legend:",
115
- show_legend_label=True,
116
- show_remove_tags_button=True,
117
- show_copy_button=False,
118
- color_map={"Error A": "blue", "Error B": "red", "Error C": "green"},
119
- )
120
-
121
- # Functions
122
-
123
- tagged.input(
124
- fn=convert_tagged_text_to_highlighted_text,
125
- inputs=[tagged, tag_id, tag_open, tag_close],
126
- outputs=high,
127
- )
128
- high.input(
129
- fn=convert_highlighted_text_to_tagged_text,
130
- inputs=[high, tag_id, tag_open, tag_close],
131
- outputs=tagged,
132
- )
133
- high.focus(
134
- fn=show_info,
135
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Focus")],
136
- outputs=None,
137
- )
138
- high.blur(
139
- fn=show_info,
140
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Blur")],
141
- outputs=None,
142
- )
143
- high.clear(
144
- fn=show_info,
145
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Remove tags")],
146
- outputs=None,
147
- )
148
-
149
- if __name__ == "__main__":
150
- demo.launch()
151
-
152
- ```
153
-
154
- ## `HighlightedTextbox`
155
-
156
- ### Initialization
157
-
158
- <table>
159
- <thead>
160
- <tr>
161
- <th align="left">name</th>
162
- <th align="left" style="width: 25%;">type</th>
163
- <th align="left">default</th>
164
- <th align="left">description</th>
165
- </tr>
166
- </thead>
167
- <tbody>
168
- <tr>
169
- <td align="left"><code>value</code></td>
170
- <td align="left" style="width: 25%;">
171
-
172
- ```python
173
- list[tuple[str, str | None]] | Callable | None
174
- ```
175
-
176
- </td>
177
- <td align="left"><code>""</code></td>
178
- <td align="left">default text to provide in textbox. If callable, the function will be called whenever the app loads to set the initial value of the component.</td>
179
- </tr>
180
-
181
- <tr>
182
- <td align="left"><code>color_map</code></td>
183
- <td align="left" style="width: 25%;">
184
-
185
- ```python
186
- dict[str, str] | None
187
- ```
188
-
189
- </td>
190
- <td align="left"><code>None</code></td>
191
- <td align="left">dictionary mapping labels to colors.</td>
192
- </tr>
193
-
194
- <tr>
195
- <td align="left"><code>show_legend</code></td>
196
- <td align="left" style="width: 25%;">
197
-
198
- ```python
199
- bool
200
- ```
201
-
202
- </td>
203
- <td align="left"><code>False</code></td>
204
- <td align="left">if True, will display legend.</td>
205
- </tr>
206
-
207
- <tr>
208
- <td align="left"><code>show_legend_label</code></td>
209
- <td align="left" style="width: 25%;">
210
-
211
- ```python
212
- bool
213
- ```
214
-
215
- </td>
216
- <td align="left"><code>False</code></td>
217
- <td align="left">if True, will display legend label.</td>
218
- </tr>
219
-
220
- <tr>
221
- <td align="left"><code>legend_label</code></td>
222
- <td align="left" style="width: 25%;">
223
-
224
- ```python
225
- str
226
- ```
227
-
228
- </td>
229
- <td align="left"><code>""</code></td>
230
- <td align="left">label to display above legend.</td>
231
- </tr>
232
-
233
- <tr>
234
- <td align="left"><code>combine_adjacent</code></td>
235
- <td align="left" style="width: 25%;">
236
-
237
- ```python
238
- bool
239
- ```
240
-
241
- </td>
242
- <td align="left"><code>False</code></td>
243
- <td align="left">if True, will combine adjacent spans with the same label.</td>
244
- </tr>
245
-
246
- <tr>
247
- <td align="left"><code>adjacent_separator</code></td>
248
- <td align="left" style="width: 25%;">
249
-
250
- ```python
251
- str
252
- ```
253
-
254
- </td>
255
- <td align="left"><code>""</code></td>
256
- <td align="left">separator to use when combining adjacent spans.</td>
257
- </tr>
258
-
259
- <tr>
260
- <td align="left"><code>label</code></td>
261
- <td align="left" style="width: 25%;">
262
-
263
- ```python
264
- str | None
265
- ```
266
-
267
- </td>
268
- <td align="left"><code>None</code></td>
269
- <td align="left">component name in interface.</td>
270
- </tr>
271
-
272
- <tr>
273
- <td align="left"><code>info</code></td>
274
- <td align="left" style="width: 25%;">
275
-
276
- ```python
277
- str | None
278
- ```
279
-
280
- </td>
281
- <td align="left"><code>None</code></td>
282
- <td align="left">None</td>
283
- </tr>
284
-
285
- <tr>
286
- <td align="left"><code>every</code></td>
287
- <td align="left" style="width: 25%;">
288
-
289
- ```python
290
- float | None
291
- ```
292
-
293
- </td>
294
- <td align="left"><code>None</code></td>
295
- <td align="left">If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.</td>
296
- </tr>
297
-
298
- <tr>
299
- <td align="left"><code>show_label</code></td>
300
- <td align="left" style="width: 25%;">
301
-
302
- ```python
303
- bool | None
304
- ```
305
-
306
- </td>
307
- <td align="left"><code>None</code></td>
308
- <td align="left">if True, will display label.</td>
309
- </tr>
310
-
311
- <tr>
312
- <td align="left"><code>container</code></td>
313
- <td align="left" style="width: 25%;">
314
-
315
- ```python
316
- bool
317
- ```
318
-
319
- </td>
320
- <td align="left"><code>True</code></td>
321
- <td align="left">If True, will place the component in a container - providing some extra padding around the border.</td>
322
- </tr>
323
-
324
- <tr>
325
- <td align="left"><code>scale</code></td>
326
- <td align="left" style="width: 25%;">
327
-
328
- ```python
329
- int | None
330
- ```
331
-
332
- </td>
333
- <td align="left"><code>None</code></td>
334
- <td align="left">relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.</td>
335
- </tr>
336
-
337
- <tr>
338
- <td align="left"><code>min_width</code></td>
339
- <td align="left" style="width: 25%;">
340
-
341
- ```python
342
- int
343
- ```
344
-
345
- </td>
346
- <td align="left"><code>160</code></td>
347
- <td align="left">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.</td>
348
- </tr>
349
-
350
- <tr>
351
- <td align="left"><code>visible</code></td>
352
- <td align="left" style="width: 25%;">
353
-
354
- ```python
355
- bool
356
- ```
357
-
358
- </td>
359
- <td align="left"><code>True</code></td>
360
- <td align="left">If False, component will be hidden.</td>
361
- </tr>
362
-
363
- <tr>
364
- <td align="left"><code>elem_id</code></td>
365
- <td align="left" style="width: 25%;">
366
-
367
- ```python
368
- str | None
369
- ```
370
-
371
- </td>
372
- <td align="left"><code>None</code></td>
373
- <td align="left">An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
374
- </tr>
375
-
376
- <tr>
377
- <td align="left"><code>autofocus</code></td>
378
- <td align="left" style="width: 25%;">
379
-
380
- ```python
381
- bool
382
- ```
383
-
384
- </td>
385
- <td align="left"><code>False</code></td>
386
- <td align="left">None</td>
387
- </tr>
388
-
389
- <tr>
390
- <td align="left"><code>autoscroll</code></td>
391
- <td align="left" style="width: 25%;">
392
-
393
- ```python
394
- bool
395
- ```
396
-
397
- </td>
398
- <td align="left"><code>True</code></td>
399
- <td align="left">If True, will automatically scroll to the bottom of the textbox when the value changes, unless the user scrolls up. If False, will not scroll to the bottom of the textbox when the value changes.</td>
400
- </tr>
401
-
402
- <tr>
403
- <td align="left"><code>interactive</code></td>
404
- <td align="left" style="width: 25%;">
405
-
406
- ```python
407
- bool
408
- ```
409
-
410
- </td>
411
- <td align="left"><code>True</code></td>
412
- <td align="left">if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.</td>
413
- </tr>
414
-
415
- <tr>
416
- <td align="left"><code>elem_classes</code></td>
417
- <td align="left" style="width: 25%;">
418
-
419
- ```python
420
- list[str] | str | None
421
- ```
422
-
423
- </td>
424
- <td align="left"><code>None</code></td>
425
- <td align="left">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.</td>
426
- </tr>
427
-
428
- <tr>
429
- <td align="left"><code>render</code></td>
430
- <td align="left" style="width: 25%;">
431
-
432
- ```python
433
- bool
434
- ```
435
-
436
- </td>
437
- <td align="left"><code>True</code></td>
438
- <td align="left">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.</td>
439
- </tr>
440
-
441
- <tr>
442
- <td align="left"><code>show_copy_button</code></td>
443
- <td align="left" style="width: 25%;">
444
-
445
- ```python
446
- bool
447
- ```
448
-
449
- </td>
450
- <td align="left"><code>False</code></td>
451
- <td align="left">If True, includes a copy button to copy the text in the textbox. Only applies if show_label is True.</td>
452
- </tr>
453
-
454
- <tr>
455
- <td align="left"><code>show_remove_tags_button</code></td>
456
- <td align="left" style="width: 25%;">
457
-
458
- ```python
459
- bool
460
- ```
461
-
462
- </td>
463
- <td align="left"><code>False</code></td>
464
- <td align="left">If True, includes a button to remove all tags from the text.</td>
465
- </tr>
466
- </tbody></table>
467
-
468
-
469
- ### Events
470
-
471
- | name | description |
472
- |:-----|:------------|
473
- | `change` | Triggered when the value of the HighlightedTextbox 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. |
474
- | `input` | This listener is triggered when the user changes the value of the HighlightedTextbox. |
475
- | `select` | Event listener for when the user selects or deselects the HighlightedTextbox. Uses event data gradio.SelectData to carry `value` referring to the label of the HighlightedTextbox, and `selected` to refer to state of the HighlightedTextbox. See EventData documentation on how to use this event data |
476
- | `submit` | This listener is triggered when the user presses the Enter key while the HighlightedTextbox is focused. |
477
- | `focus` | This listener is triggered when the HighlightedTextbox is focused. |
478
- | `blur` | This listener is triggered when the HighlightedTextbox is unfocused/blurred. |
479
- | `clear` | This listener is triggered when the user clears the HighlightedTextbox using the X button for the component. |
480
-
481
-
482
-
483
- ### User function
484
-
485
- 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).
486
-
487
- - When used as an Input, the component only impacts the input signature of the user function.
488
- - When used as an output, the component only impacts the return signature of the user function.
489
-
490
- The code snippet below is accurate in cases where the component is used as both an input and an output.
491
-
492
- - **As input:** Should return, list of (word, category) tuples, or a dictionary of two keys: "id", and "data", which is a list of (word, category) tuples.
493
-
494
- ```python
495
- def predict(
496
- value: dict
497
- ) -> list[tuple[str, str | None]] | dict | None:
498
- return value
499
- ```
500
-
 
1
+ ---
2
+ tags:
3
+ - gradio-custom-component
4
+ - gradio-template-SimpleTextbox
5
+ - highlight
6
+ - textbox
7
+ - editing
8
+ - color
9
+ title: gradio_highlightedtextbox
10
+ colorFrom: indigo
11
+ colorTo: green
12
+ sdk: docker
13
+ pinned: false
14
+ license: apache-2.0
15
+ python_version: 3.11
16
+ emoji: 🔤🖌️
17
+ short_description: Gradio component - Editable textarea supporting highlighting
18
+ ---
19
+
20
+
21
+ # Name: gradio_highlightedtextbox
22
+
23
+ Description: Editable Gradio textarea supporting highlighting
24
+
25
+ Install with: pip install gradio_highlightedtextbox
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/pyproject.toml CHANGED
@@ -39,7 +39,7 @@ dev = ["build", "twine"]
39
  space = "https://huggingface.co/spaces/gsarti/gradio_highlightedtextbox"
40
 
41
  [tool.hatch.build]
42
- artifacts = ["backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "/backend/gradio_highlightedtextbox/templates"]
43
 
44
  [tool.hatch.build.targets.wheel]
45
- packages = ["/backend/gradio_highlightedtextbox"]
 
39
  space = "https://huggingface.co/spaces/gsarti/gradio_highlightedtextbox"
40
 
41
  [tool.hatch.build]
42
+ artifacts = ["backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates"]
43
 
44
  [tool.hatch.build.targets.wheel]
45
+ packages = ["backend/gradio_highlightedtextbox"]