Spaces:
Build error
Build error
Ankur Goyal
commited on
Commit
·
418105e
1
Parent(s):
0d71988
Small cleanups
Browse files
app.py
CHANGED
@@ -175,20 +175,22 @@ def annotate_page(prediction, pages, document):
|
|
175 |
def process_question(
|
176 |
question, document, img_gallery, model, fields, output, output_table
|
177 |
):
|
|
|
|
|
|
|
|
|
178 |
if not question or document is None:
|
179 |
-
return None,
|
180 |
|
181 |
text_value = None
|
182 |
pages = [processing_utils.decode_base64_to_image(p) for p in img_gallery]
|
183 |
prediction = run_pipeline(model, question, document, 1)
|
184 |
annotate_page(prediction, pages, document)
|
185 |
|
186 |
-
field_name = question
|
187 |
-
fields = {field_name: [question], **fields}
|
188 |
output = {field_name: prediction, **output}
|
189 |
table = [[field_name, prediction.get("answer")]] + output_table.values.tolist()
|
190 |
return (
|
191 |
-
None,
|
192 |
gr.update(visible=True, value=pages),
|
193 |
fields,
|
194 |
output,
|
@@ -388,7 +390,8 @@ with gr.Blocks(css=CSS) as demo:
|
|
388 |
with gr.Tabs():
|
389 |
with gr.TabItem("Table"):
|
390 |
output_table = gr.Dataframe(
|
391 |
-
headers=["Field", "Value"],
|
|
|
392 |
elem_id="results-table"
|
393 |
)
|
394 |
|
@@ -470,23 +473,18 @@ with gr.Blocks(css=CSS) as demo:
|
|
470 |
outputs=submit_outputs,
|
471 |
)
|
472 |
|
473 |
-
question.submit
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
submit_button.click(
|
480 |
-
process_question,
|
481 |
-
inputs=[question, document, model],
|
482 |
-
outputs=[image, output, output_table],
|
483 |
-
)
|
484 |
|
485 |
-
model.change(
|
486 |
-
process_question,
|
487 |
-
inputs=[question, document, model],
|
488 |
-
outputs=[image, output, output_table],
|
489 |
-
)
|
490 |
|
491 |
example_image.change(
|
492 |
fn=load_example_document,
|
|
|
175 |
def process_question(
|
176 |
question, document, img_gallery, model, fields, output, output_table
|
177 |
):
|
178 |
+
field_name = question
|
179 |
+
if field_name is not None:
|
180 |
+
fields = {field_name: [question], **fields}
|
181 |
+
|
182 |
if not question or document is None:
|
183 |
+
return None, document, fields, output, gr.update(value=output_table)
|
184 |
|
185 |
text_value = None
|
186 |
pages = [processing_utils.decode_base64_to_image(p) for p in img_gallery]
|
187 |
prediction = run_pipeline(model, question, document, 1)
|
188 |
annotate_page(prediction, pages, document)
|
189 |
|
|
|
|
|
190 |
output = {field_name: prediction, **output}
|
191 |
table = [[field_name, prediction.get("answer")]] + output_table.values.tolist()
|
192 |
return (
|
193 |
+
None,
|
194 |
gr.update(visible=True, value=pages),
|
195 |
fields,
|
196 |
output,
|
|
|
390 |
with gr.Tabs():
|
391 |
with gr.TabItem("Table"):
|
392 |
output_table = gr.Dataframe(
|
393 |
+
headers=["Field", "Value"],
|
394 |
+
**empty_table(fields.value),
|
395 |
elem_id="results-table"
|
396 |
)
|
397 |
|
|
|
473 |
outputs=submit_outputs,
|
474 |
)
|
475 |
|
476 |
+
for action in [question.submit, submit_button.click]:
|
477 |
+
action(
|
478 |
+
fn=process_question,
|
479 |
+
inputs=[question, document, image, model, fields, output, output_table],
|
480 |
+
outputs=[question, image, fields, output, output_table],
|
481 |
+
)
|
|
|
|
|
|
|
|
|
|
|
482 |
|
483 |
+
# model.change(
|
484 |
+
# process_question,
|
485 |
+
# inputs=[question, document, model],
|
486 |
+
# outputs=[image, output, output_table],
|
487 |
+
# )
|
488 |
|
489 |
example_image.change(
|
490 |
fn=load_example_document,
|