Spaces:
Runtime error
Runtime error
ai42
commited on
Commit
·
6d2e6dd
1
Parent(s):
551b8be
Update app.py
Browse files
app.py
CHANGED
@@ -5,11 +5,13 @@ os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
5 |
from PIL import Image, ImageDraw
|
6 |
import traceback
|
7 |
|
|
|
|
|
8 |
import gradio as gr
|
9 |
|
10 |
import torch
|
11 |
from docquery import pipeline
|
12 |
-
from docquery.document import load_document,
|
13 |
from docquery.ocr_reader import get_ocr_reader
|
14 |
|
15 |
|
@@ -87,8 +89,9 @@ examples = [
|
|
87 |
],
|
88 |
[
|
89 |
"SaleData.xlsx",
|
90 |
-
|
91 |
-
|
|
|
92 |
# [
|
93 |
# "docquery.png",
|
94 |
# "How many likes does the space have?",
|
@@ -133,9 +136,12 @@ def process_path(path):
|
|
133 |
)
|
134 |
|
135 |
|
136 |
-
def process_upload(file):
|
137 |
if file:
|
138 |
return process_path(file.name)
|
|
|
|
|
|
|
139 |
else:
|
140 |
return (
|
141 |
None,
|
@@ -145,6 +151,10 @@ def process_upload(file):
|
|
145 |
gr.update(visible=False, value=None),
|
146 |
None,
|
147 |
)
|
|
|
|
|
|
|
|
|
148 |
|
149 |
|
150 |
colors = ["#64A087", "green", "black"]
|
@@ -227,7 +237,7 @@ CSS = """
|
|
227 |
padding-bottom: 2px !important;
|
228 |
padding-left: 8px !important;
|
229 |
padding-right: 8px !important;
|
230 |
-
|
231 |
}
|
232 |
.gradio-container .gr-button-primary {
|
233 |
background: linear-gradient(180deg, #CDF9BE 0%, #AFF497 100%);
|
@@ -293,19 +303,15 @@ gradio-app h2, .gradio-app h2 {
|
|
293 |
"""
|
294 |
|
295 |
with gr.Blocks(css=CSS) as demo:
|
296 |
-
gr.Markdown("#
|
297 |
-
|
298 |
-
"DocQuery (created by [Impira](https://impira.com?utm_source=huggingface&utm_medium=referral&utm_campaign=docquery_space))"
|
299 |
-
" uses LayoutLMv1 fine-tuned on DocVQA, a document visual question"
|
300 |
-
" answering dataset, as well as SQuAD, which boosts its English-language comprehension."
|
301 |
-
" To use it, simply upload an image or PDF, type a question, and click 'submit', or "
|
302 |
-
" click one of the examples to load them."
|
303 |
-
" DocQuery is MIT-licensed and available on [Github](https://github.com/impira/docquery)."
|
304 |
-
)
|
305 |
|
306 |
document = gr.Variable()
|
307 |
example_question = gr.Textbox(visible=False)
|
308 |
example_image = gr.Image(visible=False)
|
|
|
|
|
|
|
309 |
|
310 |
with gr.Row(equal_height=True):
|
311 |
with gr.Column():
|
@@ -428,6 +434,11 @@ with gr.Blocks(css=CSS) as demo:
|
|
428 |
inputs=[example_image, example_question, model],
|
429 |
outputs=[document, question, image, img_clear_button, output, output_text],
|
430 |
)
|
|
|
|
|
|
|
|
|
|
|
431 |
|
432 |
if __name__ == "__main__":
|
433 |
-
demo.launch(enable_queue=False)
|
|
|
5 |
from PIL import Image, ImageDraw
|
6 |
import traceback
|
7 |
|
8 |
+
import pandas as pd
|
9 |
+
|
10 |
import gradio as gr
|
11 |
|
12 |
import torch
|
13 |
from docquery import pipeline
|
14 |
+
from docquery.document import load_document, ImageDocumenta
|
15 |
from docquery.ocr_reader import get_ocr_reader
|
16 |
|
17 |
|
|
|
89 |
],
|
90 |
[
|
91 |
"SaleData.xlsx",
|
92 |
+
"What is the highest sale amount of televsion in east region?",
|
93 |
+
|
94 |
+
]
|
95 |
# [
|
96 |
# "docquery.png",
|
97 |
# "How many likes does the space have?",
|
|
|
136 |
)
|
137 |
|
138 |
|
139 |
+
def process_upload(file, excel_file):
|
140 |
if file:
|
141 |
return process_path(file.name)
|
142 |
+
if excel_file:
|
143 |
+
excel_data = pd.read_excel(excel_file)
|
144 |
+
return process_path(excel_file.name)
|
145 |
else:
|
146 |
return (
|
147 |
None,
|
|
|
151 |
gr.update(visible=False, value=None),
|
152 |
None,
|
153 |
)
|
154 |
+
|
155 |
+
|
156 |
+
|
157 |
+
|
158 |
|
159 |
|
160 |
colors = ["#64A087", "green", "black"]
|
|
|
237 |
padding-bottom: 2px !important;
|
238 |
padding-left: 8px !important;
|
239 |
padding-right: 8px !important;
|
240 |
+
margin-top: 10px;
|
241 |
}
|
242 |
.gradio-container .gr-button-primary {
|
243 |
background: linear-gradient(180deg, #CDF9BE 0%, #AFF497 100%);
|
|
|
303 |
"""
|
304 |
|
305 |
with gr.Blocks(css=CSS) as demo:
|
306 |
+
gr.Markdown("# Document Query Engine")
|
307 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
document = gr.Variable()
|
310 |
example_question = gr.Textbox(visible=False)
|
311 |
example_image = gr.Image(visible=False)
|
312 |
+
excel_upload = gr.File(label="Upload Excel", type="xlsx", elem_id="excel-upload-box")
|
313 |
+
|
314 |
+
excel_process_button = gr.Button("Process Excel", variant="primary", elem_id="excel-process-button")
|
315 |
|
316 |
with gr.Row(equal_height=True):
|
317 |
with gr.Column():
|
|
|
434 |
inputs=[example_image, example_question, model],
|
435 |
outputs=[document, question, image, img_clear_button, output, output_text],
|
436 |
)
|
437 |
+
upload.change(
|
438 |
+
fn=process_upload,
|
439 |
+
inputs=[upload, excel_upload],
|
440 |
+
outputs=[document, image_preview, img_clear_button, output, output_text, url_error],
|
441 |
+
)
|
442 |
|
443 |
if __name__ == "__main__":
|
444 |
+
demo.launch(enable_queue=False)
|