Spaces:
Sleeping
Sleeping
File size: 7,389 Bytes
d0c9c37 d95c01c 4acca32 d0c9c37 4acca32 d0c9c37 ca86eff d0c9c37 33f6a35 d0c9c37 33f6a35 ca86eff 33f6a35 4acca32 6fde86d ecddc77 6fde86d d0c9c37 4acca32 d0c9c37 db98dd5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
import spaces
import gradio as gr
from marker.markdown_extractor import MarkdownExtractorConfig, MarkdownExtractor
from pdf.pdf_extractor import PDFExtractorConfig, PDFExtractor
from unstructuredio.unstructured_pdf import UnstructuredIOConfig, UnstructuredIOExtractor
from indexify_extractor_sdk import Content
markdown_extractor = MarkdownExtractor()
pdf_extractor = PDFExtractor()
unstructured_extractor = UnstructuredIOExtractor()
@spaces.GPU
def use_marker(pdf_filepath):
if pdf_filepath is None:
raise gr.Error("Please provide some input PDF: upload a PDF file")
with open(pdf_filepath, "rb") as f:
pdf_data = f.read()
content = Content(content_type="application/pdf", data=pdf_data)
config = MarkdownExtractorConfig(batch_multiplier=2)
result = markdown_extractor.extract(content, config)
return result
@spaces.GPU
def use_pdf_extractor(pdf_filepath):
if pdf_filepath is None:
raise gr.Error("Please provide some input PDF: upload a PDF file")
with open(pdf_filepath, "rb") as f:
pdf_data = f.read()
content = Content(content_type="application/pdf", data=pdf_data)
config = PDFExtractorConfig(output_types=["text", "table"])
result = pdf_extractor.extract(content, config)
return result
@spaces.GPU
def use_unstructured(pdf_filepath):
if pdf_filepath is None:
raise gr.Error("Please provide some input PDF: upload a PDF file")
with open(pdf_filepath, "rb") as f:
pdf_data = f.read()
content = Content(content_type="application/pdf", data=pdf_data)
config = UnstructuredIOConfig(strategy="hi_res")
result = unstructured_extractor.extract(content, config)
return result
with gr.Blocks(theme=gr.themes.Soft()) as demo:
with gr.Tab("PDF data extraction with Marker & Indexify"):
gr.HTML("<h1 style='text-align: center'>PDF data extraction with Marker & <a href='https://getindexify.ai/'>Indexify</a></h1>")
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>")
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>")
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>")
with gr.Row():
with gr.Column():
gr.HTML(
"<p><b>Step 1:</b> Upload a PDF file from local storage.</p>"
"<p style='color: #A0A0A0;'>Use this demo for single PDF file only. "
"You can extract from PDF files continuously and try various other extractors locally with "
"<a href='https://getindexify.ai/'>Indexify</a>.</p>"
)
pdf_file_1 = gr.File(type="filepath")
with gr.Column():
gr.HTML("<p><b>Step 2:</b> Run the extractor.</p>")
go_button_1 = gr.Button(value="Run Marker extractor", variant="primary")
model_output_text_box_1 = gr.Textbox(label="Extractor Output", elem_id="model_output_text_box_1")
with gr.Row():
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>")
go_button_1.click(fn=use_marker, inputs=[pdf_file_1], outputs=[model_output_text_box_1])
with gr.Tab("PDF data extraction with PDF Extractor & Indexify"):
gr.HTML("<h1 style='text-align: center'>PDF data extraction with PDF Extractor & <a href='https://getindexify.ai/'>Indexify</a></h1>")
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>")
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>")
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/SEC_10_K_docs.ipynb' target='_blank'>extraction pipeline</a> with Indexify</h4>")
with gr.Row():
with gr.Column():
gr.HTML(
"<p><b>Step 1:</b> Upload a PDF file from local storage.</p>"
"<p style='color: #A0A0A0;'>Use this demo for single PDF file only. "
"You can extract from PDF files continuously and try various other extractors locally with "
"<a href='https://getindexify.ai/'>Indexify</a>.</p>"
)
pdf_file_2 = gr.File(type="filepath")
with gr.Column():
gr.HTML("<p><b>Step 2:</b> Run the extractor.</p>")
go_button_2 = gr.Button(value="Run PDF extractor", variant="primary")
model_output_text_box_2 = gr.Textbox(label="Extractor Output", elem_id="model_output_text_box_2")
with gr.Row():
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>")
go_button_2.click(fn=use_pdf_extractor, inputs=[pdf_file_2], outputs=[model_output_text_box_2])
with gr.Tab("PDF data extraction with Unstructured IO & Indexify"):
gr.HTML("<h1 style='text-align: center'>PDF data extraction with Unstructured IO & <a href='https://getindexify.ai/'>Indexify</a></h1>")
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>")
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>")
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>")
with gr.Row():
with gr.Column():
gr.HTML(
"<p><b>Step 1:</b> Upload a PDF file from local storage.</p>"
"<p style='color: #A0A0A0;'>Use this demo for single PDF file only. "
"You can extract from PDF files continuously and try various other extractors locally with "
"<a href='https://getindexify.ai/'>Indexify</a>.</p>"
)
pdf_file_3 = gr.File(type="filepath")
with gr.Column():
gr.HTML("<p><b>Step 2:</b> Run the extractor.</p>")
go_button_3 = gr.Button(value="Run Unstructured extractor", variant="primary")
model_output_text_box_3 = gr.Textbox(label="Extractor Output", elem_id="model_output_text_box_3")
with gr.Row():
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>")
go_button_3.click(fn=use_unstructured, inputs=[pdf_file_3], outputs=[model_output_text_box_3])
demo.queue()
demo.launch() |