Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,3 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from _app import demo as app
|
3 |
-
import os
|
4 |
-
|
5 |
-
_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[Ellipsis, 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': []}}}
|
6 |
-
|
7 |
-
abs_path = os.path.join(os.path.dirname(__file__), "css.css")
|
8 |
-
|
9 |
-
with gr.Blocks(
|
10 |
-
css=abs_path,
|
11 |
-
theme=gr.themes.Default(
|
12 |
-
font_mono=[
|
13 |
-
gr.themes.GoogleFont("Inconsolata"),
|
14 |
-
"monospace",
|
15 |
-
],
|
16 |
-
),
|
17 |
-
) as demo:
|
18 |
-
gr.Markdown(
|
19 |
-
"""
|
20 |
-
# `gradio_pdf`
|
21 |
-
|
22 |
-
<div style="display: flex; gap: 7px;">
|
23 |
-
<a href="https://pypi.org/project/gradio_pdf/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_pdf"></a>
|
24 |
-
</div>
|
25 |
-
|
26 |
-
Easily display PDFs in Gradio
|
27 |
-
""", elem_classes=["md-custom"], header_links=True)
|
28 |
-
app.render()
|
29 |
-
gr.Markdown(
|
30 |
-
"""
|
31 |
-
## Installation
|
32 |
-
|
33 |
-
```bash
|
34 |
-
pip install gradio_pdf
|
35 |
-
```
|
36 |
-
|
37 |
-
## Usage
|
38 |
-
|
39 |
-
```python
|
40 |
|
41 |
import gradio as gr
|
42 |
from _app import demo as app
|
@@ -63,7 +24,7 @@ with gr.Blocks(
|
|
63 |
<a href="https://pypi.org/project/gradio_pdf/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_pdf"></a>
|
64 |
</div>
|
65 |
|
66 |
-
|
67 |
""", elem_classes=["md-custom"], header_links=True)
|
68 |
app.render()
|
69 |
gr.Markdown(
|
@@ -127,87 +88,6 @@ if __name__ == "__main__":
|
|
127 |
|
128 |
|
129 |
|
130 |
-
gr.Markdown("""
|
131 |
-
|
132 |
-
### User function
|
133 |
-
|
134 |
-
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).
|
135 |
-
|
136 |
-
- When used as an Input, the component only impacts the input signature of the user function.
|
137 |
-
- When used as an output, the component only impacts the return signature of the user function.
|
138 |
-
|
139 |
-
The code snippet below is accurate in cases where the component is used as both an input and an output.
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
```python
|
144 |
-
def predict(
|
145 |
-
value: str
|
146 |
-
) -> str | None:
|
147 |
-
return value
|
148 |
-
```
|
149 |
-
""", elem_classes=["md-custom", "PDF-user-fn"], header_links=True)
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
demo.load(None, js=r"""function() {
|
155 |
-
const refs = {};
|
156 |
-
const user_fn_refs = {
|
157 |
-
PDF: [], };
|
158 |
-
requestAnimationFrame(() => {
|
159 |
-
|
160 |
-
Object.entries(user_fn_refs).forEach(([key, refs]) => {
|
161 |
-
if (refs.length > 0) {
|
162 |
-
const el = document.querySelector(`.${key}-user-fn`);
|
163 |
-
if (!el) return;
|
164 |
-
refs.forEach(ref => {
|
165 |
-
el.innerHTML = el.innerHTML.replace(
|
166 |
-
new RegExp("\\b"+ref+"\\b", "g"),
|
167 |
-
`<a href="#h-${ref.toLowerCase()}">${ref}</a>`
|
168 |
-
);
|
169 |
-
})
|
170 |
-
}
|
171 |
-
})
|
172 |
-
|
173 |
-
Object.entries(refs).forEach(([key, refs]) => {
|
174 |
-
if (refs.length > 0) {
|
175 |
-
const el = document.querySelector(`.${key}`);
|
176 |
-
if (!el) return;
|
177 |
-
refs.forEach(ref => {
|
178 |
-
el.innerHTML = el.innerHTML.replace(
|
179 |
-
new RegExp("\\b"+ref+"\\b", "g"),
|
180 |
-
`<a href="#h-${ref.toLowerCase()}">${ref}</a>`
|
181 |
-
);
|
182 |
-
})
|
183 |
-
}
|
184 |
-
})
|
185 |
-
})
|
186 |
-
}
|
187 |
-
|
188 |
-
""")
|
189 |
-
|
190 |
-
demo.launch()
|
191 |
-
|
192 |
-
```
|
193 |
-
""", elem_classes=["md-custom"], header_links=True)
|
194 |
-
|
195 |
-
|
196 |
-
gr.Markdown("""
|
197 |
-
## `PDF`
|
198 |
-
|
199 |
-
### Initialization
|
200 |
-
""", elem_classes=["md-custom"], header_links=True)
|
201 |
-
|
202 |
-
gr.ParamViewer(value=_docs["PDF"]["members"]["__init__"], linkify=[])
|
203 |
-
|
204 |
-
|
205 |
-
gr.Markdown("### Events")
|
206 |
-
gr.ParamViewer(value=_docs["PDF"]["events"], linkify=['Event'])
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
gr.Markdown("""
|
212 |
|
213 |
### User function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
import gradio as gr
|
3 |
from _app import demo as app
|
|
|
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
|
28 |
""", elem_classes=["md-custom"], header_links=True)
|
29 |
app.render()
|
30 |
gr.Markdown(
|
|
|
88 |
|
89 |
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
gr.Markdown("""
|
92 |
|
93 |
### User function
|