Update app.py
Browse files
app.py
CHANGED
@@ -19,14 +19,13 @@ def ensure_list(x):
|
|
19 |
else:
|
20 |
return [x]
|
21 |
|
|
|
22 |
CHECKPOINTS = {
|
23 |
"LayoutLMv1 🦉": "impira/layoutlm-document-qa",
|
24 |
"LayoutLMv1 for Invoices 💸": "impira/layoutlm-invoices",
|
25 |
"Donut 🍩": "naver-clova-ix/donut-base-finetuned-docvqa",
|
26 |
-
"CQI Assistant Eyes 🤖": "cloudqi/CQI_Visual_Question_Awnser_PT_v0"
|
27 |
}
|
28 |
|
29 |
-
|
30 |
PIPELINES = {}
|
31 |
|
32 |
|
@@ -75,15 +74,15 @@ def normalize_bbox(box, width, height, padding=0.005):
|
|
75 |
examples = [
|
76 |
[
|
77 |
"invoice.png",
|
78 |
-
"
|
79 |
],
|
80 |
[
|
81 |
"contract.jpeg",
|
82 |
-
"
|
83 |
],
|
84 |
[
|
85 |
"statement.png",
|
86 |
-
"
|
87 |
],
|
88 |
# [
|
89 |
# "docquery.png",
|
@@ -96,9 +95,9 @@ examples = [
|
|
96 |
]
|
97 |
|
98 |
question_files = {
|
99 |
-
"
|
100 |
-
"
|
101 |
-
"
|
102 |
}
|
103 |
|
104 |
|
@@ -289,7 +288,7 @@ gradio-app h2, .gradio-app h2 {
|
|
289 |
"""
|
290 |
|
291 |
with gr.Blocks(css=CSS) as demo:
|
292 |
-
gr.Markdown("
|
293 |
|
294 |
document = gr.Variable()
|
295 |
example_question = gr.Textbox(visible=False)
|
@@ -298,9 +297,9 @@ with gr.Blocks(css=CSS) as demo:
|
|
298 |
with gr.Row(equal_height=True):
|
299 |
with gr.Column():
|
300 |
with gr.Row():
|
301 |
-
gr.Markdown("## 1.
|
302 |
img_clear_button = gr.Button(
|
303 |
-
"
|
304 |
)
|
305 |
image = gr.Gallery(visible=False)
|
306 |
with gr.Row(equal_height=True):
|
@@ -329,10 +328,10 @@ with gr.Blocks(css=CSS) as demo:
|
|
329 |
)
|
330 |
|
331 |
with gr.Column() as col:
|
332 |
-
gr.Markdown("## 2.
|
333 |
question = gr.Textbox(
|
334 |
label="Question",
|
335 |
-
placeholder="e.g.
|
336 |
lines=1,
|
337 |
max_lines=1,
|
338 |
)
|
@@ -345,11 +344,11 @@ with gr.Blocks(css=CSS) as demo:
|
|
345 |
with gr.Row():
|
346 |
clear_button = gr.Button("Clear", variant="secondary")
|
347 |
submit_button = gr.Button(
|
348 |
-
"
|
349 |
)
|
350 |
with gr.Column():
|
351 |
output_text = gr.Textbox(
|
352 |
-
label="
|
353 |
)
|
354 |
output = gr.JSON(label="Output", visible=False)
|
355 |
|
@@ -418,4 +417,4 @@ with gr.Blocks(css=CSS) as demo:
|
|
418 |
)
|
419 |
|
420 |
if __name__ == "__main__":
|
421 |
-
demo.launch(enable_queue=False)
|
|
|
19 |
else:
|
20 |
return [x]
|
21 |
|
22 |
+
|
23 |
CHECKPOINTS = {
|
24 |
"LayoutLMv1 🦉": "impira/layoutlm-document-qa",
|
25 |
"LayoutLMv1 for Invoices 💸": "impira/layoutlm-invoices",
|
26 |
"Donut 🍩": "naver-clova-ix/donut-base-finetuned-docvqa",
|
|
|
27 |
}
|
28 |
|
|
|
29 |
PIPELINES = {}
|
30 |
|
31 |
|
|
|
74 |
examples = [
|
75 |
[
|
76 |
"invoice.png",
|
77 |
+
"What is the invoice number?",
|
78 |
],
|
79 |
[
|
80 |
"contract.jpeg",
|
81 |
+
"What is the purchase amount?",
|
82 |
],
|
83 |
[
|
84 |
"statement.png",
|
85 |
+
"What are net sales for 2020?",
|
86 |
],
|
87 |
# [
|
88 |
# "docquery.png",
|
|
|
95 |
]
|
96 |
|
97 |
question_files = {
|
98 |
+
"What are net sales for 2020?": "statement.pdf",
|
99 |
+
"How many likes does the space have?": "https://huggingface.co/spaces/impira/docquery",
|
100 |
+
"What is the title of post number 5?": "https://news.ycombinator.com",
|
101 |
}
|
102 |
|
103 |
|
|
|
288 |
"""
|
289 |
|
290 |
with gr.Blocks(css=CSS) as demo:
|
291 |
+
gr.Markdown("# DocQuery: Document Query Engine")
|
292 |
|
293 |
document = gr.Variable()
|
294 |
example_question = gr.Textbox(visible=False)
|
|
|
297 |
with gr.Row(equal_height=True):
|
298 |
with gr.Column():
|
299 |
with gr.Row():
|
300 |
+
gr.Markdown("## 1. Select a file", elem_id="select-a-file")
|
301 |
img_clear_button = gr.Button(
|
302 |
+
"Clear", variant="secondary", elem_id="file-clear", visible=False
|
303 |
)
|
304 |
image = gr.Gallery(visible=False)
|
305 |
with gr.Row(equal_height=True):
|
|
|
328 |
)
|
329 |
|
330 |
with gr.Column() as col:
|
331 |
+
gr.Markdown("## 2. Ask a question")
|
332 |
question = gr.Textbox(
|
333 |
label="Question",
|
334 |
+
placeholder="e.g. What is the invoice number?",
|
335 |
lines=1,
|
336 |
max_lines=1,
|
337 |
)
|
|
|
344 |
with gr.Row():
|
345 |
clear_button = gr.Button("Clear", variant="secondary")
|
346 |
submit_button = gr.Button(
|
347 |
+
"Submit", variant="primary", elem_id="submit-button"
|
348 |
)
|
349 |
with gr.Column():
|
350 |
output_text = gr.Textbox(
|
351 |
+
label="Top Answer", visible=False, elem_id="answer"
|
352 |
)
|
353 |
output = gr.JSON(label="Output", visible=False)
|
354 |
|
|
|
417 |
)
|
418 |
|
419 |
if __name__ == "__main__":
|
420 |
+
demo.launch(enable_queue=False)
|