freddyaboulton HF staff commited on
Commit
467ae2b
1 Parent(s): dd5ca28

Update space.py

Browse files
Files changed (1) hide show
  1. space.py +123 -2
space.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  from app import demo as app
4
  import os
5
 
6
- _docs = {'PDF': {'description': 'A base class for defining methods that all input/output components should have.', 'members': {'__init__': {'value': {'type': 'typing.Any', 'default': 'None', 'description': None}, 'height': {'type': 'int | None', 'default': 'None', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[Ellipsis, typing.Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | None', 'description': "The output data received by the component from the user's function in the backend."}}, 'preprocess': {'return': {'type': 'str', 'description': "The preprocessed input data sent to the user's function in the backend."}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'upload': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'PDF': []}}}
7
 
8
  abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
 
@@ -21,7 +21,7 @@ with gr.Blocks(
21
  # `gradio_pdf`
22
 
23
  <div style="display: flex; gap: 7px;">
24
- <a href="https://pypi.org/project/gradio_pdf/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_pdf"></a>
25
  </div>
26
 
27
  Easily display PDFs in Gradio
@@ -39,6 +39,46 @@ pip install gradio_pdf
39
 
40
  ```python
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  import gradio as gr
43
  from gradio_pdf import PDF
44
  from pdf2image import convert_from_path
@@ -69,6 +109,87 @@ demo = gr.Interface(
69
  if __name__ == "__main__":
70
  demo.launch()
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  ```
73
  """, elem_classes=["md-custom"], header_links=True)
74
 
 
3
  from app import demo as app
4
  import os
5
 
6
+ _docs = {'PDF': {'description': 'PDF COMPONENT', 'members': {'__init__': {'value': {'type': 'Any', 'default': 'None', 'description': None}, 'height': {'type': 'int | None', 'default': 'None', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[Ellipsis, Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}, 'starting_page': {'type': 'int | None', 'default': '1', 'description': None}}, 'postprocess': {'value': {'type': 'str | None', 'description': "The output data received by the component from the user's function in the backend."}}, 'preprocess': {'return': {'type': 'str', 'description': "The preprocessed input data sent to the user's function in the backend."}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'upload': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'PDF': []}}}
7
 
8
  abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
 
 
21
  # `gradio_pdf`
22
 
23
  <div style="display: flex; gap: 7px;">
24
+ <a href="https://pypi.org/project/gradio_pdf/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_pdf"></a> <a href="https://github.com/freddyaboulton/gradio-pdf/issues" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Issues-white?logo=github&logoColor=black"></a> <a href="https://huggingface.co/spaces/freddyaboulton/gradio_pdf/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
  Easily display PDFs in Gradio
 
39
 
40
  ```python
41
 
42
+ import gradio as gr
43
+ from _app import demo as app
44
+ import os
45
+
46
+ _docs = {'PDF': {'description': 'A base class for defining methods that all input/output components should have.', 'members': {'__init__': {'value': {'type': 'Any', 'default': 'None', 'description': None}, 'height': {'type': 'int | None', 'default': 'None', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[..., Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | None', 'description': None}}, 'preprocess': {'return': {'type': 'str', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'upload': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'PDF': []}}}
47
+
48
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
49
+
50
+ with gr.Blocks(
51
+ css=abs_path,
52
+ theme=gr.themes.Default(
53
+ font_mono=[
54
+ gr.themes.GoogleFont("Inconsolata"),
55
+ "monospace",
56
+ ],
57
+ ),
58
+ ) as demo:
59
+ gr.Markdown(
60
+ \"\"\"
61
+ # `gradio_pdf`
62
+
63
+ <div style="display: flex; gap: 7px;">
64
+ <a href="https://pypi.org/project/gradio_pdf/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_pdf"></a> <a href="https://github.com/freddyaboulton/gradio-pdf/issues" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Issues-white?logo=github&logoColor=black"></a> <a href="https://huggingface.co/spaces/freddyaboulton/gradio_pdf/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
65
+ </div>
66
+
67
+ Easily display PDFs in Gradio
68
+ \"\"\", elem_classes=["md-custom"], header_links=True)
69
+ app.render()
70
+ gr.Markdown(
71
+ \"\"\"
72
+ ## Installation
73
+
74
+ ```bash
75
+ pip install gradio_pdf
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ ```python
81
+
82
  import gradio as gr
83
  from gradio_pdf import PDF
84
  from pdf2image import convert_from_path
 
109
  if __name__ == "__main__":
110
  demo.launch()
111
 
112
+ ```
113
+ \"\"\", elem_classes=["md-custom"], header_links=True)
114
+
115
+
116
+ gr.Markdown(\"\"\"
117
+ ## `PDF`
118
+
119
+ ### Initialization
120
+ \"\"\", elem_classes=["md-custom"], header_links=True)
121
+
122
+ gr.ParamViewer(value=_docs["PDF"]["members"]["__init__"], linkify=[])
123
+
124
+
125
+ gr.Markdown("### Events")
126
+ gr.ParamViewer(value=_docs["PDF"]["events"], linkify=['Event'])
127
+
128
+
129
+
130
+
131
+ gr.Markdown(\"\"\"
132
+
133
+ ### User function
134
+
135
+ 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).
136
+
137
+ - When used as an Input, the component only impacts the input signature of the user function.
138
+ - When used as an output, the component only impacts the return signature of the user function.
139
+
140
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
141
+
142
+
143
+
144
+ ```python
145
+ def predict(
146
+ value: str
147
+ ) -> str | None:
148
+ return value
149
+ ```
150
+ \"\"\", elem_classes=["md-custom", "PDF-user-fn"], header_links=True)
151
+
152
+
153
+
154
+
155
+ demo.load(None, js=r\"\"\"function() {
156
+ const refs = {};
157
+ const user_fn_refs = {
158
+ PDF: [], };
159
+ requestAnimationFrame(() => {
160
+
161
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
162
+ if (refs.length > 0) {
163
+ const el = document.querySelector(`.${key}-user-fn`);
164
+ if (!el) return;
165
+ refs.forEach(ref => {
166
+ el.innerHTML = el.innerHTML.replace(
167
+ new RegExp("\\b"+ref+"\\b", "g"),
168
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
169
+ );
170
+ })
171
+ }
172
+ })
173
+
174
+ Object.entries(refs).forEach(([key, refs]) => {
175
+ if (refs.length > 0) {
176
+ const el = document.querySelector(`.${key}`);
177
+ if (!el) return;
178
+ refs.forEach(ref => {
179
+ el.innerHTML = el.innerHTML.replace(
180
+ new RegExp("\\b"+ref+"\\b", "g"),
181
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
182
+ );
183
+ })
184
+ }
185
+ })
186
+ })
187
+ }
188
+
189
+ \"\"\")
190
+
191
+ demo.launch()
192
+
193
  ```
194
  """, elem_classes=["md-custom"], header_links=True)
195