Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,7 @@ def ensure_list(x):
|
|
22 |
|
23 |
CHECKPOINTS = {
|
24 |
"CQI FLMv1 Base PT": "impira/layoutlm-document-qa",
|
25 |
-
"CQI FLMv1
|
26 |
"CQI FDonut": "naver-clova-ix/donut-base-finetuned-docvqa",
|
27 |
"CQI Assistant Eyes 🤖": "cloudqi/CQI_Visual_Question_Awnser_PT_v0"
|
28 |
}
|
@@ -46,6 +46,8 @@ def run_pipeline(model, question, document, top_k):
|
|
46 |
return pipeline(question=question, **document.context, top_k=top_k)
|
47 |
|
48 |
|
|
|
|
|
49 |
def lift_word_boxes(document, page):
|
50 |
return document.context["image"][page][1]
|
51 |
|
@@ -59,6 +61,7 @@ def expand_bbox(word_boxes):
|
|
59 |
return [min_x, min_y, max_x, max_y]
|
60 |
|
61 |
|
|
|
62 |
def normalize_bbox(box, width, height, padding=0.005):
|
63 |
min_x, min_y, max_x, max_y = [c / 1000 for c in box]
|
64 |
if padding != 0:
|
@@ -72,22 +75,30 @@ def normalize_bbox(box, width, height, padding=0.005):
|
|
72 |
examples = [
|
73 |
[
|
74 |
"invoice.png",
|
75 |
-
"
|
76 |
],
|
77 |
[
|
78 |
"contract.jpeg",
|
79 |
-
"
|
80 |
],
|
81 |
[
|
82 |
"statement.png",
|
83 |
-
"
|
84 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
]
|
86 |
|
87 |
question_files = {
|
88 |
-
"
|
89 |
-
"
|
90 |
-
"
|
91 |
}
|
92 |
|
93 |
|
@@ -193,6 +204,17 @@ CSS = """
|
|
193 |
#short-upload-box .w-full {
|
194 |
min-height: 10rem !important;
|
195 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
#select-a-file {
|
197 |
width: 100%;
|
198 |
}
|
@@ -267,7 +289,7 @@ gradio-app h2, .gradio-app h2 {
|
|
267 |
"""
|
268 |
|
269 |
with gr.Blocks(css=CSS) as demo:
|
270 |
-
gr.Markdown("##
|
271 |
|
272 |
document = gr.Variable()
|
273 |
example_question = gr.Textbox(visible=False)
|
@@ -276,9 +298,9 @@ with gr.Blocks(css=CSS) as demo:
|
|
276 |
with gr.Row(equal_height=True):
|
277 |
with gr.Column():
|
278 |
with gr.Row():
|
279 |
-
gr.Markdown("## 1.
|
280 |
img_clear_button = gr.Button(
|
281 |
-
"
|
282 |
)
|
283 |
image = gr.Gallery(visible=False)
|
284 |
with gr.Row(equal_height=True):
|
@@ -307,10 +329,10 @@ with gr.Blocks(css=CSS) as demo:
|
|
307 |
)
|
308 |
|
309 |
with gr.Column() as col:
|
310 |
-
gr.Markdown("## 2.
|
311 |
question = gr.Textbox(
|
312 |
label="Question",
|
313 |
-
placeholder="e.g.
|
314 |
lines=1,
|
315 |
max_lines=1,
|
316 |
)
|
@@ -323,11 +345,11 @@ with gr.Blocks(css=CSS) as demo:
|
|
323 |
with gr.Row():
|
324 |
clear_button = gr.Button("Clear", variant="secondary")
|
325 |
submit_button = gr.Button(
|
326 |
-
"
|
327 |
)
|
328 |
with gr.Column():
|
329 |
output_text = gr.Textbox(
|
330 |
-
label="
|
331 |
)
|
332 |
output = gr.JSON(label="Output", visible=False)
|
333 |
|
@@ -396,4 +418,4 @@ with gr.Blocks(css=CSS) as demo:
|
|
396 |
)
|
397 |
|
398 |
if __name__ == "__main__":
|
399 |
-
demo.launch(enable_queue=False)
|
|
|
22 |
|
23 |
CHECKPOINTS = {
|
24 |
"CQI FLMv1 Base PT": "impira/layoutlm-document-qa",
|
25 |
+
"CQI FLMv1 para Faturas 💸": "impira/layoutlm-invoices",
|
26 |
"CQI FDonut": "naver-clova-ix/donut-base-finetuned-docvqa",
|
27 |
"CQI Assistant Eyes 🤖": "cloudqi/CQI_Visual_Question_Awnser_PT_v0"
|
28 |
}
|
|
|
46 |
return pipeline(question=question, **document.context, top_k=top_k)
|
47 |
|
48 |
|
49 |
+
# TODO: Move into docquery
|
50 |
+
# TODO: Support words past the first page (or window?)
|
51 |
def lift_word_boxes(document, page):
|
52 |
return document.context["image"][page][1]
|
53 |
|
|
|
61 |
return [min_x, min_y, max_x, max_y]
|
62 |
|
63 |
|
64 |
+
# LayoutLM boxes are normalized to 0, 1000
|
65 |
def normalize_bbox(box, width, height, padding=0.005):
|
66 |
min_x, min_y, max_x, max_y = [c / 1000 for c in box]
|
67 |
if padding != 0:
|
|
|
75 |
examples = [
|
76 |
[
|
77 |
"invoice.png",
|
78 |
+
"Qual é o número da fatura?",
|
79 |
],
|
80 |
[
|
81 |
"contract.jpeg",
|
82 |
+
"Qual é o valor da compra?",
|
83 |
],
|
84 |
[
|
85 |
"statement.png",
|
86 |
+
"Quais são as vendas líquidas para 2020?",
|
87 |
],
|
88 |
+
# [
|
89 |
+
# "docquery.png",
|
90 |
+
# "How many likes does the space have?",
|
91 |
+
# ],
|
92 |
+
# [
|
93 |
+
# "hacker_news.png",
|
94 |
+
# "What is the title of post number 5?",
|
95 |
+
# ],
|
96 |
]
|
97 |
|
98 |
question_files = {
|
99 |
+
"Quais são as vendas líquidas para 2020?": "statement.pdf",
|
100 |
+
"Quantas curtidas tem o espaço?": "https://huggingface.co/spaces/impira/docquery",
|
101 |
+
"Qual é o título do post número 5?": "https://news.ycombinator.com",
|
102 |
}
|
103 |
|
104 |
|
|
|
204 |
#short-upload-box .w-full {
|
205 |
min-height: 10rem !important;
|
206 |
}
|
207 |
+
/* I think something like this can be used to re-shape
|
208 |
+
* the table
|
209 |
+
*/
|
210 |
+
/*
|
211 |
+
.gr-samples-table tr {
|
212 |
+
display: inline;
|
213 |
+
}
|
214 |
+
.gr-samples-table .p-2 {
|
215 |
+
width: 100px;
|
216 |
+
}
|
217 |
+
*/
|
218 |
#select-a-file {
|
219 |
width: 100%;
|
220 |
}
|
|
|
289 |
"""
|
290 |
|
291 |
with gr.Blocks(css=CSS) as demo:
|
292 |
+
gr.Markdown("## Mecanismo de Consulta de Documentos")
|
293 |
|
294 |
document = gr.Variable()
|
295 |
example_question = gr.Textbox(visible=False)
|
|
|
298 |
with gr.Row(equal_height=True):
|
299 |
with gr.Column():
|
300 |
with gr.Row():
|
301 |
+
gr.Markdown("## 1. Selecione um arquivo", elem_id="select-a-file")
|
302 |
img_clear_button = gr.Button(
|
303 |
+
"Limpar", variant="secondary", elem_id="file-clear", visible=False
|
304 |
)
|
305 |
image = gr.Gallery(visible=False)
|
306 |
with gr.Row(equal_height=True):
|
|
|
329 |
)
|
330 |
|
331 |
with gr.Column() as col:
|
332 |
+
gr.Markdown("## 2. Faça uma pergunta")
|
333 |
question = gr.Textbox(
|
334 |
label="Question",
|
335 |
+
placeholder="e.g. Qual é o número da fatura?",
|
336 |
lines=1,
|
337 |
max_lines=1,
|
338 |
)
|
|
|
345 |
with gr.Row():
|
346 |
clear_button = gr.Button("Clear", variant="secondary")
|
347 |
submit_button = gr.Button(
|
348 |
+
"Enviar", variant="primary", elem_id="submit-button"
|
349 |
)
|
350 |
with gr.Column():
|
351 |
output_text = gr.Textbox(
|
352 |
+
label="Resposta principal", visible=False, elem_id="answer"
|
353 |
)
|
354 |
output = gr.JSON(label="Output", visible=False)
|
355 |
|
|
|
418 |
)
|
419 |
|
420 |
if __name__ == "__main__":
|
421 |
+
demo.launch(enable_queue=False)
|