<h1 style='text-align: center; margin-bottom: 1rem'> Modelly PDF 📕 </h1>
<div style="display: flex; flex-direction: row; justify-content: center">
<img style="display: block; padding-right: 5px; height: 20px;" alt="Static Badge" src="https://img.shields.io/pypi/v/modelly_pdf">
<a href="https://github.com/freddyaboulton/modelly-pdf" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/github-white?logo=github&logoColor=black"></a>
</div>
Easily display PDFs in Modelly
## Installation
```bash
pip install modelly_pdf
```
## Usage
```python
import modelly as gr
from modelly_pdf import PDF
from pdf2image import convert_from_path
from transformers import pipeline
from pathlib import Path
dir_ = Path(__file__).parent
p = pipeline(
"document-question-answering",
model="impira/layoutlm-document-qa",
)
def qa(question: str, doc: str) -> str:
img = convert_from_path(doc)[0]
output = p(img, question)
return sorted(output, key=lambda x: x["score"], reverse=True)[0]['answer']
demo = gr.Interface(
qa,
[gr.Textbox(label="Question"), PDF(label="Document")],
gr.Textbox(),
examples=[["What is the total gross worth?", str(dir_ / "invoice_2.pdf")],
["Whos is being invoiced?", str(dir_ / "sample_invoice.pdf")]]
)
if __name__ == "__main__":
demo.launch()
```
## `PDF`
### Initialization
<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left" style="width: 25%;">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>value</code></td>
<td align="left" style="width: 25%;">
```python
Any
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>height</code></td>
<td align="left" style="width: 25%;">
```python
int | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>label</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>info</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>show_label</code></td>
<td align="left" style="width: 25%;">
```python
bool | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>container</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>True</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>scale</code></td>
<td align="left" style="width: 25%;">
```python
int | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>min_width</code></td>
<td align="left" style="width: 25%;">
```python
int | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>interactive</code></td>
<td align="left" style="width: 25%;">
```python
bool | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>visible</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>True</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>elem_id</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>elem_classes</code></td>
<td align="left" style="width: 25%;">
```python
list[str] | str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>render</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>True</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>load_fn</code></td>
<td align="left" style="width: 25%;">
```python
Callable[Ellipsis, Any] | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>every</code></td>
<td align="left" style="width: 25%;">
```python
float | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>starting_page</code></td>
<td align="left" style="width: 25%;">
```python
int | None
```
</td>
<td align="left"><code>1</code></td>
<td align="left">None</td>
</tr>
</tbody></table>
### Events
| name | description |
|:-----|:------------|
| `change` | |
| `upload` | |
### User function
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).
- When used as an Input, the component only impacts the input signature of the user function.
- When used as an output, the component only impacts the return signature of the user function.
The code snippet below is accurate in cases where the component is used as both an input and an output.
- **As output:** Is passed, the preprocessed input data sent to the user's function in the backend.
- **As input:** Should return, the output data received by the component from the user's function in the backend.
```python
def predict(
value: str
) -> str | None:
return value
```
Raw data
{
"_id": null,
"home_page": null,
"name": "modelly-pdf",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "Document QA, Documents, PDF, modelly, modelly custom component, modelly-template-Fallback",
"author": null,
"author_email": "Md Sulaiman <dev.sulaiman@icloud.com>",
"download_url": null,
"platform": null,
"description": "<h1 style='text-align: center; margin-bottom: 1rem'> Modelly PDF \ud83d\udcd5 </h1>\n\n<div style=\"display: flex; flex-direction: row; justify-content: center\">\n<img style=\"display: block; padding-right: 5px; height: 20px;\" alt=\"Static Badge\" src=\"https://img.shields.io/pypi/v/modelly_pdf\"> \n<a href=\"https://github.com/freddyaboulton/modelly-pdf\" target=\"_blank\"><img alt=\"Static Badge\" src=\"https://img.shields.io/badge/github-white?logo=github&logoColor=black\"></a>\n</div>\n\nEasily display PDFs in Modelly\n\n## Installation\n\n```bash\npip install modelly_pdf\n```\n\n## Usage\n\n```python\n\nimport modelly as gr\nfrom modelly_pdf import PDF\nfrom pdf2image import convert_from_path\nfrom transformers import pipeline\nfrom pathlib import Path\n\ndir_ = Path(__file__).parent\n\np = pipeline(\n \"document-question-answering\",\n model=\"impira/layoutlm-document-qa\",\n)\n\ndef qa(question: str, doc: str) -> str:\n img = convert_from_path(doc)[0]\n output = p(img, question)\n return sorted(output, key=lambda x: x[\"score\"], reverse=True)[0]['answer']\n\n\ndemo = gr.Interface(\n qa,\n [gr.Textbox(label=\"Question\"), PDF(label=\"Document\")],\n gr.Textbox(),\n examples=[[\"What is the total gross worth?\", str(dir_ / \"invoice_2.pdf\")],\n [\"Whos is being invoiced?\", str(dir_ / \"sample_invoice.pdf\")]]\n)\n\nif __name__ == \"__main__\":\n demo.launch()\n```\n\n\n## `PDF`\n\n### Initialization\n\n<table>\n<thead>\n<tr>\n<th align=\"left\">name</th>\n<th align=\"left\" style=\"width: 25%;\">type</th>\n<th align=\"left\">default</th>\n<th align=\"left\">description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\"><code>value</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nAny\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>height</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>label</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>info</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>show_label</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>container</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>scale</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>min_width</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>interactive</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>visible</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_id</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_classes</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nlist[str] | str | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>render</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>load_fn</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nCallable[Ellipsis, Any] | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>every</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nfloat | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>starting_page</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>1</code></td>\n<td align=\"left\">None</td>\n</tr>\n</tbody></table>\n\n\n### Events\n\n| name | description |\n|:-----|:------------|\n| `change` | |\n| `upload` | |\n\n\n\n### User function\n\nThe impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).\n\n- When used as an Input, the component only impacts the input signature of the user function.\n- When used as an output, the component only impacts the return signature of the user function.\n\nThe code snippet below is accurate in cases where the component is used as both an input and an output.\n\n- **As output:** Is passed, the preprocessed input data sent to the user's function in the backend.\n- **As input:** Should return, the output data received by the component from the user's function in the backend.\n\n ```python\n def predict(\n value: str\n ) -> str | None:\n return value\n ```\n \n",
"bugtrack_url": null,
"license": null,
"summary": "Easily display PDFs in Modelly",
"version": "0.0.21",
"project_urls": null,
"split_keywords": [
"document qa",
" documents",
" pdf",
" modelly",
" modelly custom component",
" modelly-template-fallback"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0e1d3ed39ba85541450445fe3d62383716dcfcf402a663daaf7d2c5cb70c1262",
"md5": "92d6bd046889ea86d4f3b390d8ca8072",
"sha256": "d47ef73db26bb3c3482cc1c144f3f26da3308f721cb2ada4fe742768df273bca"
},
"downloads": -1,
"filename": "modelly_pdf-0.0.21-py3-none-any.whl",
"has_sig": false,
"md5_digest": "92d6bd046889ea86d4f3b390d8ca8072",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 4414,
"upload_time": "2025-01-09T02:26:06",
"upload_time_iso_8601": "2025-01-09T02:26:06.308783Z",
"url": "https://files.pythonhosted.org/packages/0e/1d/3ed39ba85541450445fe3d62383716dcfcf402a663daaf7d2c5cb70c1262/modelly_pdf-0.0.21-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-09 02:26:06",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "modelly-pdf"
}