rishiraj commited on
Commit
4acca32
1 Parent(s): f9f6787

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py CHANGED
@@ -2,10 +2,12 @@ import spaces
2
  import gradio as gr
3
  from marker.markdown_extractor import MarkdownExtractorConfig, MarkdownExtractor
4
  from pdf.pdf_extractor import PDFExtractorConfig, PDFExtractor
 
5
  from indexify_extractor_sdk import Content
6
 
7
  markdown_extractor = MarkdownExtractor()
8
  pdf_extractor = PDFExtractor()
 
9
 
10
  @spaces.GPU
11
  def use_marker(pdf_filepath):
@@ -29,6 +31,17 @@ def use_pdf_extractor(pdf_filepath):
29
  result = pdf_extractor.extract(content, config)
30
  return result
31
 
 
 
 
 
 
 
 
 
 
 
 
32
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
33
  with gr.Tab("PDF data extraction with Marker & Indexify"):
34
  gr.HTML("<h1 style='text-align: center'>PDF data extraction with Marker & <a href='https://getindexify.ai/'>Indexify</a></h1>")
@@ -80,5 +93,30 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
80
 
81
  go_button_2.click(fn=use_pdf_extractor, inputs=[pdf_file_2], outputs=[model_output_text_box_2])
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  demo.queue()
84
  demo.launch()
 
2
  import gradio as gr
3
  from marker.markdown_extractor import MarkdownExtractorConfig, MarkdownExtractor
4
  from pdf.pdf_extractor import PDFExtractorConfig, PDFExtractor
5
+ from unstructuredio.unstructured_pdf import UnstructuredIOConfig, UnstructuredIOExtractor
6
  from indexify_extractor_sdk import Content
7
 
8
  markdown_extractor = MarkdownExtractor()
9
  pdf_extractor = PDFExtractor()
10
+ unstructured_extractor = UnstructuredIOExtractor()
11
 
12
  @spaces.GPU
13
  def use_marker(pdf_filepath):
 
31
  result = pdf_extractor.extract(content, config)
32
  return result
33
 
34
+ @spaces.GPU
35
+ def use_unstructured(pdf_filepath):
36
+ if pdf_filepath is None:
37
+ raise gr.Error("Please provide some input PDF: upload a PDF file")
38
+ with open(pdf_filepath, "rb") as f:
39
+ pdf_data = f.read()
40
+ content = Content(content_type="application/pdf", data=pdf_data)
41
+ config = UnstructuredIOConfig(strategy="hi_res")
42
+ result = unstructured_extractor.extract(content, config)
43
+ return result
44
+
45
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
46
  with gr.Tab("PDF data extraction with Marker & Indexify"):
47
  gr.HTML("<h1 style='text-align: center'>PDF data extraction with Marker & <a href='https://getindexify.ai/'>Indexify</a></h1>")
 
93
 
94
  go_button_2.click(fn=use_pdf_extractor, inputs=[pdf_file_2], outputs=[model_output_text_box_2])
95
 
96
+ with gr.Tab("PDF data extraction with Unstructured IO & Indexify"):
97
+ gr.HTML("<h1 style='text-align: center'>PDF data extraction with Unstructured IO & <a href='https://getindexify.ai/'>Indexify</a></h1>")
98
+ gr.HTML("<p style='text-align: center'>Indexify is a scalable realtime and continuous indexing and structured extraction engine for unstructured data to build generative AI applications</p>")
99
+ gr.HTML("<h3 style='text-align: center'>If you like this demo, please ⭐ Star us on <a href='https://github.com/tensorlakeai/indexify' target='_blank'>GitHub</a>!</h3>")
100
+ gr.HTML("<h4 style='text-align: center'>Here's an example notebook that demonstrates how to build a continuous <a href='https://github.com/tensorlakeai/indexify/blob/main/docs/docs/examples/efficient_rag.ipynb' target='_blank'>extraction pipeline</a> with Indexify</h4>")
101
+
102
+ with gr.Row():
103
+ with gr.Column():
104
+ gr.HTML(
105
+ "<p><b>Step 1:</b> Upload a PDF file from local storage.</p>"
106
+ "<p style='color: #A0A0A0;'>Use this demo for single PDF file only. "
107
+ "You can extract from PDF files continuously and try various other extractors locally with "
108
+ "<a href='https://getindexify.ai/'>Indexify</a>.</p>"
109
+ )
110
+ pdf_file_3 = gr.File(type="filepath")
111
+ with gr.Column():
112
+ gr.HTML("<p><b>Step 2:</b> Run the extractor.</p>")
113
+ go_button_3 = gr.Button(value="Run Unstructured extractor", variant="primary")
114
+ model_output_text_box_3 = gr.Textbox(label="Extractor Output", elem_id="model_output_text_box_3")
115
+
116
+ with gr.Row():
117
+ gr.HTML("<p style='text-align: center'>Developed with 🫶 by <a href='https://getindexify.ai/' target='_blank'>Indexify</a> | a <a href='https://www.tensorlake.ai/' target='_blank'>Tensorlake</a> product</p>")
118
+
119
+ go_button_3.click(fn=use_unstructured, inputs=[pdf_file_3], outputs=[model_output_text_box_3])
120
+
121
  demo.queue()
122
  demo.launch()