ai42 commited on
Commit
44f8cdc
·
1 Parent(s): e0a9079

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -1,15 +1,17 @@
1
  import os
 
2
 
3
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
4
 
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, ImageDocument
13
  from docquery.ocr_reader import get_ocr_reader
14
 
15
 
@@ -86,9 +88,10 @@ examples = [
86
  "What are net sales for 2020?",
87
  ],
88
  [
89
- "SaleData.xlsx",
90
-
91
- ],
 
92
  # [
93
  # "docquery.png",
94
  # "How many likes does the space have?",
@@ -103,6 +106,8 @@ question_files = {
103
  "What are net sales for 2020?": "statement.pdf",
104
  "How many likes does the space have?": "https://huggingface.co/spaces/impira/docquery",
105
  "What is the title of post number 5?": "https://news.ycombinator.com",
 
 
106
  }
107
 
108
 
@@ -145,6 +150,10 @@ def process_upload(file):
145
  gr.update(visible=False, value=None),
146
  None,
147
  )
 
 
 
 
148
 
149
 
150
  colors = ["#64A087", "green", "black"]
@@ -227,7 +236,7 @@ CSS = """
227
  padding-bottom: 2px !important;
228
  padding-left: 8px !important;
229
  padding-right: 8px !important;
230
- margin-top: 10px;
231
  }
232
  .gradio-container .gr-button-primary {
233
  background: linear-gradient(180deg, #CDF9BE 0%, #AFF497 100%);
@@ -293,19 +302,15 @@ gradio-app h2, .gradio-app h2 {
293
  """
294
 
295
  with gr.Blocks(css=CSS) as demo:
296
- gr.Markdown("# DocQuery: Document Query Engine")
297
- gr.Markdown(
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():
@@ -429,5 +434,6 @@ with gr.Blocks(css=CSS) as demo:
429
  outputs=[document, question, image, img_clear_button, output, output_text],
430
  )
431
 
 
432
  if __name__ == "__main__":
433
  demo.launch(enable_queue=False)
 
1
  import os
2
+ import io
3
 
4
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
5
 
6
  from PIL import Image, ImageDraw
7
  import traceback
8
 
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
 
 
88
  "What are net sales for 2020?",
89
  ],
90
  [
91
+ "saleData.pdf",
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?",
 
106
  "What are net sales for 2020?": "statement.pdf",
107
  "How many likes does the space have?": "https://huggingface.co/spaces/impira/docquery",
108
  "What is the title of post number 5?": "https://news.ycombinator.com",
109
+ "What is the highest sale amount of television in east region?": "SaleData.pdf", # Add the PDF file here
110
+
111
  }
112
 
113
 
 
150
  gr.update(visible=False, value=None),
151
  None,
152
  )
153
+
154
+
155
+
156
+
157
 
158
 
159
  colors = ["#64A087", "green", "black"]
 
236
  padding-bottom: 2px !important;
237
  padding-left: 8px !important;
238
  padding-right: 8px !important;
239
+ margin-top: 10px;
240
  }
241
  .gradio-container .gr-button-primary {
242
  background: linear-gradient(180deg, #CDF9BE 0%, #AFF497 100%);
 
302
  """
303
 
304
  with gr.Blocks(css=CSS) as demo:
305
+ gr.Markdown("# Document Query Engine")
306
+
 
 
 
 
 
 
 
307
 
308
  document = gr.Variable()
309
  example_question = gr.Textbox(visible=False)
310
  example_image = gr.Image(visible=False)
311
+ excel_upload = gr.File(label="Upload Excel", type="xlsx", elem_id="excel-upload-box")
312
+
313
+ excel_process_button = gr.Button("Process Excel", variant="primary", elem_id="excel-process-button")
314
 
315
  with gr.Row(equal_height=True):
316
  with gr.Column():
 
434
  outputs=[document, question, image, img_clear_button, output, output_text],
435
  )
436
 
437
+
438
  if __name__ == "__main__":
439
  demo.launch(enable_queue=False)