Spaces:
Runtime error
Runtime error
update app.py
Browse filesTranslations: All non-English text has been translated into English.
Project Name: Changed the title of the project to "Modular Visual Analytics for Prompt Engineering."
Label Changes: Updated various labels, placeholders, and Markdown texts to be in English.
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,8 +46,6 @@ def run_pipeline(model, question, document, top_k):
|
|
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,7 +59,6 @@ def expand_bbox(word_boxes):
|
|
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,30 +72,22 @@ 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",
|
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 |
-
"
|
100 |
-
"
|
101 |
-
"
|
102 |
}
|
103 |
|
104 |
|
@@ -204,17 +193,6 @@ CSS = """
|
|
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,7 +267,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 +276,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 +307,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 +323,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 +396,4 @@ with gr.Blocks(css=CSS) as demo:
|
|
418 |
)
|
419 |
|
420 |
if __name__ == "__main__":
|
421 |
-
demo.launch(enable_queue=False)
|
|
|
22 |
|
23 |
CHECKPOINTS = {
|
24 |
"CQI FLMv1 Base PT": "impira/layoutlm-document-qa",
|
25 |
+
"CQI FLMv1 for Invoices 💸": "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 |
def lift_word_boxes(document, page):
|
50 |
return document.context["image"][page][1]
|
51 |
|
|
|
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 |
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 the net sales for 2020?",
|
84 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
]
|
86 |
|
87 |
question_files = {
|
88 |
+
"What are the net sales for 2020?": "statement.pdf",
|
89 |
+
"How many likes does the space have?": "https://huggingface.co/spaces/impira/docquery",
|
90 |
+
"What is the title of post number 5?": "https://news.ycombinator.com",
|
91 |
}
|
92 |
|
93 |
|
|
|
193 |
#short-upload-box .w-full {
|
194 |
min-height: 10rem !important;
|
195 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
#select-a-file {
|
197 |
width: 100%;
|
198 |
}
|
|
|
267 |
"""
|
268 |
|
269 |
with gr.Blocks(css=CSS) as demo:
|
270 |
+
gr.Markdown("## Modular Visual Analytics for Prompt Engineering")
|
271 |
|
272 |
document = gr.Variable()
|
273 |
example_question = gr.Textbox(visible=False)
|
|
|
276 |
with gr.Row(equal_height=True):
|
277 |
with gr.Column():
|
278 |
with gr.Row():
|
279 |
+
gr.Markdown("## 1. Select a file", elem_id="select-a-file")
|
280 |
img_clear_button = gr.Button(
|
281 |
+
"Clear", variant="secondary", elem_id="file-clear", visible=False
|
282 |
)
|
283 |
image = gr.Gallery(visible=False)
|
284 |
with gr.Row(equal_height=True):
|
|
|
307 |
)
|
308 |
|
309 |
with gr.Column() as col:
|
310 |
+
gr.Markdown("## 2. Ask a question")
|
311 |
question = gr.Textbox(
|
312 |
label="Question",
|
313 |
+
placeholder="e.g. What is the invoice number?",
|
314 |
lines=1,
|
315 |
max_lines=1,
|
316 |
)
|
|
|
323 |
with gr.Row():
|
324 |
clear_button = gr.Button("Clear", variant="secondary")
|
325 |
submit_button = gr.Button(
|
326 |
+
"Submit", variant="primary", elem_id="submit-button"
|
327 |
)
|
328 |
with gr.Column():
|
329 |
output_text = gr.Textbox(
|
330 |
+
label="Main Answer", visible=False, elem_id="answer"
|
331 |
)
|
332 |
output = gr.JSON(label="Output", visible=False)
|
333 |
|
|
|
396 |
)
|
397 |
|
398 |
if __name__ == "__main__":
|
399 |
+
demo.launch(enable_queue=False)
|