abidlabs HF staff commited on
Commit
4f55ed1
1 Parent(s): 8406e90

Upload folder using huggingface_hub

Browse files
Dockerfile CHANGED
@@ -5,6 +5,10 @@ WORKDIR /code
5
 
6
  COPY --link --chown=1000 . .
7
 
 
 
 
 
8
  RUN pip install --no-cache-dir -r requirements.txt
9
 
10
  ENV PYTHONUNBUFFERED=1 GRADIO_ALLOW_FLAGGING=never GRADIO_NUM_PORTS=1 GRADIO_SERVER_NAME=0.0.0.0 GRADIO_SERVER_PORT=7860 SYSTEM=spaces
 
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
README.md CHANGED
@@ -1,10 +1,17 @@
1
 
2
  ---
3
- tags: [gradio-custom-component, gradio-template-SimpleTextbox]
4
  title: gradio_rich_textbox V0.2.0
5
- colorFrom: blue
6
  colorTo: green
7
  sdk: docker
8
  pinned: false
9
  license: apache-2.0
10
  ---
 
 
 
 
 
 
 
 
1
 
2
  ---
3
+ tags: [gradio-custom-component,machine learning,reproducibility,visualization,gradio,gradio-template-SimpleTextbox]
4
  title: gradio_rich_textbox V0.2.0
5
+ colorFrom: green
6
  colorTo: green
7
  sdk: docker
8
  pinned: false
9
  license: apache-2.0
10
  ---
11
+
12
+
13
+ # Name: gradio_rich_textbox
14
+
15
+ Description: Gradio custom component for rich text input
16
+
17
+ Install with: pip install gradio_rich_textbox
app.py CHANGED
@@ -13,4 +13,5 @@ demo = gr.Interface(
13
  )
14
 
15
 
16
- demo.launch()
 
 
13
  )
14
 
15
 
16
+ if __name__ == "__main__":
17
+ demo.launch()
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
+ }
space.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'RichTextbox': {'description': 'Creates a very simple textbox for user to enter string input or display string output.', 'members': {'__init__': {'value': {'type': 'str | 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.'}, 'placeholder': {'type': 'str | None', 'default': 'None', 'description': 'placeholder hint to provide behind textbox.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'component name in interface.'}, '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.'}, '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.'}, 'interactive': {'type': 'bool | None', 'default': 'None', '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.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': 'If False, component will be hidden.'}, 'rtl': {'type': 'bool', 'default': 'False', 'description': 'If True and `type` is "text", sets the direction of the text to right-to-left (cursor appears on the left of the text). Default is False, which renders cursor on the right.'}, '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.'}}, 'postprocess': {'y': {'type': 'str | None', 'description': 'function output to postprocess.'}, 'value': {'type': 'str | None', 'description': 'function output to postprocess.'}}, 'preprocess': {'return': {'type': 'str | None', 'description': 'text'}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the RichTextbox 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 RichTextbox.'}, 'submit': {'type': None, 'default': None, 'description': 'This listener is triggered when the user presses the Enter key while the RichTextbox is focused.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'RichTextbox': []}}}
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_rich_textbox`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <a href="https://pypi.org/project/gradio_rich_textbox/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_rich_textbox"></a>
25
+ </div>
26
+
27
+ Gradio custom component for rich text input
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_rich_textbox
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+
42
+ import gradio as gr
43
+ from gradio_rich_textbox import RichTextbox
44
+
45
+
46
+ example = RichTextbox().example_inputs()
47
+
48
+ demo = gr.Interface(
49
+ lambda x:x,
50
+ RichTextbox(), # interactive version of your component
51
+ RichTextbox(), # static version of your component
52
+ examples=[[example]], # uncomment this line to view the "example version" of your component
53
+ )
54
+
55
+
56
+ if __name__ == "__main__":
57
+ demo.launch()
58
+
59
+ ```
60
+ """, elem_classes=["md-custom"], header_links=True)
61
+
62
+
63
+ gr.Markdown("""
64
+ ## `RichTextbox`
65
+
66
+ ### Initialization
67
+ """, elem_classes=["md-custom"], header_links=True)
68
+
69
+ gr.ParamViewer(value=_docs["RichTextbox"]["members"]["__init__"], linkify=[])
70
+
71
+
72
+ gr.Markdown("### Events")
73
+ gr.ParamViewer(value=_docs["RichTextbox"]["events"], linkify=['Event'])
74
+
75
+
76
+
77
+
78
+ gr.Markdown("""
79
+
80
+ ### User function
81
+
82
+ 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).
83
+
84
+ - When used as an Input, the component only impacts the input signature of the user function.
85
+ - When used as an output, the component only impacts the return signature of the user function.
86
+
87
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
88
+
89
+ - **As input:** Is passed, text.
90
+ - **As output:** Should return, function output to postprocess.
91
+
92
+ ```python
93
+ def predict(
94
+ value: str | None
95
+ ) -> str | None:
96
+ return value
97
+ ```
98
+ """, elem_classes=["md-custom", "RichTextbox-user-fn"], header_links=True)
99
+
100
+
101
+
102
+
103
+ demo.load(None, js=r"""function() {
104
+ const refs = {};
105
+ const user_fn_refs = {
106
+ RichTextbox: [], };
107
+ requestAnimationFrame(() => {
108
+
109
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
110
+ if (refs.length > 0) {
111
+ const el = document.querySelector(`.${key}-user-fn`);
112
+ if (!el) return;
113
+ refs.forEach(ref => {
114
+ el.innerHTML = el.innerHTML.replace(
115
+ new RegExp("\\b"+ref+"\\b", "g"),
116
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
117
+ );
118
+ })
119
+ }
120
+ })
121
+
122
+ Object.entries(refs).forEach(([key, refs]) => {
123
+ if (refs.length > 0) {
124
+ const el = document.querySelector(`.${key}`);
125
+ if (!el) return;
126
+ refs.forEach(ref => {
127
+ el.innerHTML = el.innerHTML.replace(
128
+ new RegExp("\\b"+ref+"\\b", "g"),
129
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
130
+ );
131
+ })
132
+ }
133
+ })
134
+ })
135
+ }
136
+
137
+ """)
138
+
139
+ demo.launch()
src/README.md CHANGED
@@ -1,10 +1,249 @@
1
 
2
- # gradio_rich_textbox
3
- A Custom Gradio component.
4
 
5
- ## Example usage
 
 
 
 
 
 
 
 
6
 
7
  ```python
 
8
  import gradio as gr
9
  from gradio_rich_textbox import RichTextbox
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ # `gradio_rich_textbox`
3
+ <a href="https://pypi.org/project/gradio_rich_textbox/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_rich_textbox"></a>
4
 
5
+ Gradio custom component for rich text input
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install gradio_rich_textbox
11
+ ```
12
+
13
+ ## Usage
14
 
15
  ```python
16
+
17
  import gradio as gr
18
  from gradio_rich_textbox import RichTextbox
19
+
20
+
21
+ example = RichTextbox().example_inputs()
22
+
23
+ demo = gr.Interface(
24
+ lambda x:x,
25
+ RichTextbox(), # interactive version of your component
26
+ RichTextbox(), # static version of your component
27
+ examples=[[example]], # uncomment this line to view the "example version" of your component
28
+ )
29
+
30
+
31
+ if __name__ == "__main__":
32
+ demo.launch()
33
+
34
+ ```
35
+
36
+ ## `RichTextbox`
37
+
38
+ ### Initialization
39
+
40
+ <table>
41
+ <thead>
42
+ <tr>
43
+ <th align="left">name</th>
44
+ <th align="left" style="width: 25%;">type</th>
45
+ <th align="left">default</th>
46
+ <th align="left">description</th>
47
+ </tr>
48
+ </thead>
49
+ <tbody>
50
+ <tr>
51
+ <td align="left"><code>value</code></td>
52
+ <td align="left" style="width: 25%;">
53
+
54
+ ```python
55
+ str | Callable | None
56
+ ```
57
+
58
+ </td>
59
+ <td align="left"><code>""</code></td>
60
+ <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>
61
+ </tr>
62
+
63
+ <tr>
64
+ <td align="left"><code>placeholder</code></td>
65
+ <td align="left" style="width: 25%;">
66
+
67
+ ```python
68
+ str | None
69
+ ```
70
+
71
+ </td>
72
+ <td align="left"><code>None</code></td>
73
+ <td align="left">placeholder hint to provide behind textbox.</td>
74
+ </tr>
75
+
76
+ <tr>
77
+ <td align="left"><code>label</code></td>
78
+ <td align="left" style="width: 25%;">
79
+
80
+ ```python
81
+ str | None
82
+ ```
83
+
84
+ </td>
85
+ <td align="left"><code>None</code></td>
86
+ <td align="left">component name in interface.</td>
87
+ </tr>
88
+
89
+ <tr>
90
+ <td align="left"><code>every</code></td>
91
+ <td align="left" style="width: 25%;">
92
+
93
+ ```python
94
+ float | None
95
+ ```
96
+
97
+ </td>
98
+ <td align="left"><code>None</code></td>
99
+ <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>
100
+ </tr>
101
+
102
+ <tr>
103
+ <td align="left"><code>show_label</code></td>
104
+ <td align="left" style="width: 25%;">
105
+
106
+ ```python
107
+ bool | None
108
+ ```
109
+
110
+ </td>
111
+ <td align="left"><code>None</code></td>
112
+ <td align="left">if True, will display label.</td>
113
+ </tr>
114
+
115
+ <tr>
116
+ <td align="left"><code>scale</code></td>
117
+ <td align="left" style="width: 25%;">
118
+
119
+ ```python
120
+ int | None
121
+ ```
122
+
123
+ </td>
124
+ <td align="left"><code>None</code></td>
125
+ <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>
126
+ </tr>
127
+
128
+ <tr>
129
+ <td align="left"><code>min_width</code></td>
130
+ <td align="left" style="width: 25%;">
131
+
132
+ ```python
133
+ int
134
+ ```
135
+
136
+ </td>
137
+ <td align="left"><code>160</code></td>
138
+ <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>
139
+ </tr>
140
+
141
+ <tr>
142
+ <td align="left"><code>interactive</code></td>
143
+ <td align="left" style="width: 25%;">
144
+
145
+ ```python
146
+ bool | None
147
+ ```
148
+
149
+ </td>
150
+ <td align="left"><code>None</code></td>
151
+ <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>
152
+ </tr>
153
+
154
+ <tr>
155
+ <td align="left"><code>visible</code></td>
156
+ <td align="left" style="width: 25%;">
157
+
158
+ ```python
159
+ bool
160
+ ```
161
+
162
+ </td>
163
+ <td align="left"><code>True</code></td>
164
+ <td align="left">If False, component will be hidden.</td>
165
+ </tr>
166
+
167
+ <tr>
168
+ <td align="left"><code>rtl</code></td>
169
+ <td align="left" style="width: 25%;">
170
+
171
+ ```python
172
+ bool
173
+ ```
174
+
175
+ </td>
176
+ <td align="left"><code>False</code></td>
177
+ <td align="left">If True and `type` is "text", sets the direction of the text to right-to-left (cursor appears on the left of the text). Default is False, which renders cursor on the right.</td>
178
+ </tr>
179
+
180
+ <tr>
181
+ <td align="left"><code>elem_id</code></td>
182
+ <td align="left" style="width: 25%;">
183
+
184
+ ```python
185
+ str | None
186
  ```
187
+
188
+ </td>
189
+ <td align="left"><code>None</code></td>
190
+ <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>
191
+ </tr>
192
+
193
+ <tr>
194
+ <td align="left"><code>elem_classes</code></td>
195
+ <td align="left" style="width: 25%;">
196
+
197
+ ```python
198
+ list[str] | str | None
199
+ ```
200
+
201
+ </td>
202
+ <td align="left"><code>None</code></td>
203
+ <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>
204
+ </tr>
205
+
206
+ <tr>
207
+ <td align="left"><code>render</code></td>
208
+ <td align="left" style="width: 25%;">
209
+
210
+ ```python
211
+ bool
212
+ ```
213
+
214
+ </td>
215
+ <td align="left"><code>True</code></td>
216
+ <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>
217
+ </tr>
218
+ </tbody></table>
219
+
220
+
221
+ ### Events
222
+
223
+ | name | description |
224
+ |:-----|:------------|
225
+ | `change` | Triggered when the value of the RichTextbox 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. |
226
+ | `input` | This listener is triggered when the user changes the value of the RichTextbox. |
227
+ | `submit` | This listener is triggered when the user presses the Enter key while the RichTextbox is focused. |
228
+
229
+
230
+
231
+ ### User function
232
+
233
+ 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).
234
+
235
+ - When used as an Input, the component only impacts the input signature of the user function.
236
+ - When used as an output, the component only impacts the return signature of the user function.
237
+
238
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
239
+
240
+ - **As output:** Is passed, text.
241
+ - **As input:** Should return, function output to postprocess.
242
+
243
+ ```python
244
+ def predict(
245
+ value: str | None
246
+ ) -> str | None:
247
+ return value
248
+ ```
249
+
src/backend/gradio_rich_textbox/richtextbox.pyi CHANGED
@@ -102,7 +102,6 @@ class RichTextbox(FormComponent):
102
  inputs: Component | Sequence[Component] | set[Component] | None = None,
103
  outputs: Component | Sequence[Component] | None = None,
104
  api_name: str | None | Literal[False] = None,
105
- status_tracker: None = None,
106
  scroll_to_output: bool = False,
107
  show_progress: Literal["full", "minimal", "hidden"] = "full",
108
  queue: bool | None = None,
@@ -113,7 +112,10 @@ class RichTextbox(FormComponent):
113
  cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
114
  every: float | None = None,
115
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
116
- js: str | None = None,) -> Dependency:
 
 
 
117
  """
118
  Parameters:
119
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
@@ -131,6 +133,9 @@ class RichTextbox(FormComponent):
131
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
132
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
133
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
 
 
 
134
  """
135
  ...
136
 
@@ -139,7 +144,6 @@ class RichTextbox(FormComponent):
139
  inputs: Component | Sequence[Component] | set[Component] | None = None,
140
  outputs: Component | Sequence[Component] | None = None,
141
  api_name: str | None | Literal[False] = None,
142
- status_tracker: None = None,
143
  scroll_to_output: bool = False,
144
  show_progress: Literal["full", "minimal", "hidden"] = "full",
145
  queue: bool | None = None,
@@ -150,7 +154,10 @@ class RichTextbox(FormComponent):
150
  cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
151
  every: float | None = None,
152
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
153
- js: str | None = None,) -> Dependency:
 
 
 
154
  """
155
  Parameters:
156
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
@@ -168,6 +175,9 @@ class RichTextbox(FormComponent):
168
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
169
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
170
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
 
 
 
171
  """
172
  ...
173
 
@@ -176,7 +186,6 @@ class RichTextbox(FormComponent):
176
  inputs: Component | Sequence[Component] | set[Component] | None = None,
177
  outputs: Component | Sequence[Component] | None = None,
178
  api_name: str | None | Literal[False] = None,
179
- status_tracker: None = None,
180
  scroll_to_output: bool = False,
181
  show_progress: Literal["full", "minimal", "hidden"] = "full",
182
  queue: bool | None = None,
@@ -187,7 +196,10 @@ class RichTextbox(FormComponent):
187
  cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
188
  every: float | None = None,
189
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
190
- js: str | None = None,) -> Dependency:
 
 
 
191
  """
192
  Parameters:
193
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
@@ -205,5 +217,8 @@ class RichTextbox(FormComponent):
205
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
206
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
207
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
 
 
 
208
  """
209
  ...
 
102
  inputs: Component | Sequence[Component] | set[Component] | None = None,
103
  outputs: Component | Sequence[Component] | None = None,
104
  api_name: str | None | Literal[False] = None,
 
105
  scroll_to_output: bool = False,
106
  show_progress: Literal["full", "minimal", "hidden"] = "full",
107
  queue: bool | None = None,
 
112
  cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
113
  every: float | None = None,
114
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
115
+ js: str | None = None,
116
+ concurrency_limit: int | None | Literal["default"] = "default",
117
+ concurrency_id: str | None = None,
118
+ show_api: bool = True) -> Dependency:
119
  """
120
  Parameters:
121
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
 
133
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
134
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
135
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
136
+ concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
137
+ concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
138
+ show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps to use this event. If fn is None, show_api will automatically be set to False.
139
  """
140
  ...
141
 
 
144
  inputs: Component | Sequence[Component] | set[Component] | None = None,
145
  outputs: Component | Sequence[Component] | None = None,
146
  api_name: str | None | Literal[False] = None,
 
147
  scroll_to_output: bool = False,
148
  show_progress: Literal["full", "minimal", "hidden"] = "full",
149
  queue: bool | None = None,
 
154
  cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
155
  every: float | None = None,
156
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
157
+ js: str | None = None,
158
+ concurrency_limit: int | None | Literal["default"] = "default",
159
+ concurrency_id: str | None = None,
160
+ show_api: bool = True) -> Dependency:
161
  """
162
  Parameters:
163
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
 
175
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
176
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
177
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
178
+ concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
179
+ concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
180
+ show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps to use this event. If fn is None, show_api will automatically be set to False.
181
  """
182
  ...
183
 
 
186
  inputs: Component | Sequence[Component] | set[Component] | None = None,
187
  outputs: Component | Sequence[Component] | None = None,
188
  api_name: str | None | Literal[False] = None,
 
189
  scroll_to_output: bool = False,
190
  show_progress: Literal["full", "minimal", "hidden"] = "full",
191
  queue: bool | None = None,
 
196
  cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
197
  every: float | None = None,
198
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
199
+ js: str | None = None,
200
+ concurrency_limit: int | None | Literal["default"] = "default",
201
+ concurrency_id: str | None = None,
202
+ show_api: bool = True) -> Dependency:
203
  """
204
  Parameters:
205
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
 
217
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
218
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
219
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
220
+ concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
221
+ concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
222
+ show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps to use this event. If fn is None, show_api will automatically be set to False.
223
  """
224
  ...
src/demo/app.py CHANGED
@@ -13,4 +13,5 @@ demo = gr.Interface(
13
  )
14
 
15
 
16
- demo.launch()
 
 
13
  )
14
 
15
 
16
+ if __name__ == "__main__":
17
+ demo.launch()
src/demo/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
+ }
src/demo/space.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'RichTextbox': {'description': 'Creates a very simple textbox for user to enter string input or display string output.', 'members': {'__init__': {'value': {'type': 'str | 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.'}, 'placeholder': {'type': 'str | None', 'default': 'None', 'description': 'placeholder hint to provide behind textbox.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'component name in interface.'}, '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.'}, '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.'}, 'interactive': {'type': 'bool | None', 'default': 'None', '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.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': 'If False, component will be hidden.'}, 'rtl': {'type': 'bool', 'default': 'False', 'description': 'If True and `type` is "text", sets the direction of the text to right-to-left (cursor appears on the left of the text). Default is False, which renders cursor on the right.'}, '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.'}}, 'postprocess': {'y': {'type': 'str | None', 'description': 'function output to postprocess.'}, 'value': {'type': 'str | None', 'description': 'function output to postprocess.'}}, 'preprocess': {'return': {'type': 'str | None', 'description': 'text'}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the RichTextbox 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 RichTextbox.'}, 'submit': {'type': None, 'default': None, 'description': 'This listener is triggered when the user presses the Enter key while the RichTextbox is focused.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'RichTextbox': []}}}
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_rich_textbox`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <a href="https://pypi.org/project/gradio_rich_textbox/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_rich_textbox"></a>
25
+ </div>
26
+
27
+ Gradio custom component for rich text input
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_rich_textbox
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+
42
+ import gradio as gr
43
+ from gradio_rich_textbox import RichTextbox
44
+
45
+
46
+ example = RichTextbox().example_inputs()
47
+
48
+ demo = gr.Interface(
49
+ lambda x:x,
50
+ RichTextbox(), # interactive version of your component
51
+ RichTextbox(), # static version of your component
52
+ examples=[[example]], # uncomment this line to view the "example version" of your component
53
+ )
54
+
55
+
56
+ if __name__ == "__main__":
57
+ demo.launch()
58
+
59
+ ```
60
+ """, elem_classes=["md-custom"], header_links=True)
61
+
62
+
63
+ gr.Markdown("""
64
+ ## `RichTextbox`
65
+
66
+ ### Initialization
67
+ """, elem_classes=["md-custom"], header_links=True)
68
+
69
+ gr.ParamViewer(value=_docs["RichTextbox"]["members"]["__init__"], linkify=[])
70
+
71
+
72
+ gr.Markdown("### Events")
73
+ gr.ParamViewer(value=_docs["RichTextbox"]["events"], linkify=['Event'])
74
+
75
+
76
+
77
+
78
+ gr.Markdown("""
79
+
80
+ ### User function
81
+
82
+ 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).
83
+
84
+ - When used as an Input, the component only impacts the input signature of the user function.
85
+ - When used as an output, the component only impacts the return signature of the user function.
86
+
87
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
88
+
89
+ - **As input:** Is passed, text.
90
+ - **As output:** Should return, function output to postprocess.
91
+
92
+ ```python
93
+ def predict(
94
+ value: str | None
95
+ ) -> str | None:
96
+ return value
97
+ ```
98
+ """, elem_classes=["md-custom", "RichTextbox-user-fn"], header_links=True)
99
+
100
+
101
+
102
+
103
+ demo.load(None, js=r"""function() {
104
+ const refs = {};
105
+ const user_fn_refs = {
106
+ RichTextbox: [], };
107
+ requestAnimationFrame(() => {
108
+
109
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
110
+ if (refs.length > 0) {
111
+ const el = document.querySelector(`.${key}-user-fn`);
112
+ if (!el) return;
113
+ refs.forEach(ref => {
114
+ el.innerHTML = el.innerHTML.replace(
115
+ new RegExp("\\b"+ref+"\\b", "g"),
116
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
117
+ );
118
+ })
119
+ }
120
+ })
121
+
122
+ Object.entries(refs).forEach(([key, refs]) => {
123
+ if (refs.length > 0) {
124
+ const el = document.querySelector(`.${key}`);
125
+ if (!el) return;
126
+ refs.forEach(ref => {
127
+ el.innerHTML = el.innerHTML.replace(
128
+ new RegExp("\\b"+ref+"\\b", "g"),
129
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
130
+ );
131
+ })
132
+ }
133
+ })
134
+ })
135
+ }
136
+
137
+ """)
138
+
139
+ demo.launch()
src/pyproject.toml CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "gradio_rich_textbox"
11
- version = "0.2.0"
12
  description = "Gradio custom component for rich text input"
13
  readme = "README.md"
14
  license = "Apache-2.0"
 
8
 
9
  [project]
10
  name = "gradio_rich_textbox"
11
+ version = "0.3.0"
12
  description = "Gradio custom component for rich text input"
13
  readme = "README.md"
14
  license = "Apache-2.0"