Update app.py
Browse files
app.py
CHANGED
|
@@ -22,6 +22,7 @@ def ensure_list(x):
|
|
| 22 |
|
| 23 |
CHECKPOINTS = {
|
| 24 |
"LayoutLMv1": "impira/layoutlm-document-qa",
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
PIPELINES = {}
|
|
@@ -68,7 +69,34 @@ def normalize_bbox(box, width, height, padding=0.005):
|
|
| 68 |
max_y = min(max_y + padding, 1)
|
| 69 |
return [min_x * width, min_y * height, max_x * width, max_y * height]
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
def process_path(path):
|
|
@@ -297,6 +325,10 @@ with gr.Blocks(css=CSS) as demo:
|
|
| 297 |
)
|
| 298 |
gr.Markdown("— or —")
|
| 299 |
upload = gr.File(label=None, interactive=True, elem_id="short-upload-box")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
|
| 301 |
with gr.Column() as col:
|
| 302 |
gr.Markdown("## 2. Ask a question")
|
|
|
|
| 22 |
|
| 23 |
CHECKPOINTS = {
|
| 24 |
"LayoutLMv1": "impira/layoutlm-document-qa",
|
| 25 |
+
"LayoutLMv1 for Invoices 💸": "impira/layoutlm-invoices",
|
| 26 |
}
|
| 27 |
|
| 28 |
PIPELINES = {}
|
|
|
|
| 69 |
max_y = min(max_y + padding, 1)
|
| 70 |
return [min_x * width, min_y * height, max_x * width, max_y * height]
|
| 71 |
|
| 72 |
+
examples = [
|
| 73 |
+
[
|
| 74 |
+
"invoice.png",
|
| 75 |
+
"What is the invoice number?",
|
| 76 |
+
],
|
| 77 |
+
[
|
| 78 |
+
"contract.jpeg",
|
| 79 |
+
"What is the purchase amount?",
|
| 80 |
+
],
|
| 81 |
+
[
|
| 82 |
+
"statement.png",
|
| 83 |
+
"What are net sales for 2020?",
|
| 84 |
+
],
|
| 85 |
+
# [
|
| 86 |
+
# "docquery.png",
|
| 87 |
+
# "How many likes does the space have?",
|
| 88 |
+
# ],
|
| 89 |
+
# [
|
| 90 |
+
# "hacker_news.png",
|
| 91 |
+
# "What is the title of post number 5?",
|
| 92 |
+
# ],
|
| 93 |
+
]
|
| 94 |
+
|
| 95 |
+
question_files = {
|
| 96 |
+
"What are net sales for 2020?": "statement.pdf",
|
| 97 |
+
"How many likes does the space have?": "https://huggingface.co/spaces/impira/docquery",
|
| 98 |
+
"What is the title of post number 5?": "https://news.ycombinator.com",
|
| 99 |
+
}
|
| 100 |
|
| 101 |
|
| 102 |
def process_path(path):
|
|
|
|
| 325 |
)
|
| 326 |
gr.Markdown("— or —")
|
| 327 |
upload = gr.File(label=None, interactive=True, elem_id="short-upload-box")
|
| 328 |
+
gr.Examples(
|
| 329 |
+
examples=examples,
|
| 330 |
+
inputs=[example_image, example_question],
|
| 331 |
+
)
|
| 332 |
|
| 333 |
with gr.Column() as col:
|
| 334 |
gr.Markdown("## 2. Ask a question")
|