rishiraj's picture
Update app.py
ca86eff verified
raw
history blame
No virus
9.85 kB
import spaces
import gradio as gr
from marker.markdown_extractor import MarkdownExtractorConfig, MarkdownExtractor
from pdf.pdf_extractor import PDFExtractorConfig, PDFExtractor
from gemini.gemini_extractor import GeminiExtractorConfig, GeminiExtractor
from oai.oai_extractor import OAIExtractorConfig, OAIExtractor
from indexify_extractor_sdk import Content
markdown_extractor = MarkdownExtractor()
pdf_extractor = PDFExtractor()
gemini_extractor = GeminiExtractor()
oai_extractor = OAIExtractor()
@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
with gr.Blocks(title="PDF data extraction with Marker & Indexify") as marker_demo:
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 = gr.File(type="filepath")
with gr.Column():
gr.HTML("<p><b>Step 2:</b> Run the extractor.</p>")
go_button = gr.Button(value="Run extractor", variant="primary")
model_output_text_box = gr.Textbox(label="Extractor Output", elem_id="model_output_text_box")
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.click(fn=use_marker, inputs=[pdf_file], outputs=[model_output_text_box])
@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
with gr.Blocks(title="PDF data extraction with PDF Extractor & Indexify") as pdf_demo:
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 = gr.File(type="filepath")
with gr.Column():
gr.HTML("<p><b>Step 2:</b> Run the extractor.</p>")
go_button = gr.Button(value="Run extractor", variant="primary")
model_output_text_box = gr.Textbox(label="Extractor Output", elem_id="model_output_text_box")
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.click(fn=use_pdf_extractor, inputs=[pdf_file], outputs=[model_output_text_box])
@spaces.GPU
def use_gemini(pdf_filepath, key):
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 = GeminiExtractorConfig(prompt="Extract all text from the document.", model_name="gemini-1.5-flash", key=key)
result = gemini_extractor.extract(content, config)
return result
with gr.Blocks(title="PDF data extraction with Gemini & Indexify") as gemini_demo:
gr.HTML("<h1 style='text-align: center'>PDF data extraction with Gemini & <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/multimodal_gemini.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 = gr.File(type="filepath")
gr.HTML("<p><b>Step 2:</b> Enter your API key.</p>")
key = gr.Textbox(info="Please enter your GEMINI_API_KEY", label="Key:")
with gr.Column():
gr.HTML("<p><b>Step 3:</b> Run the extractor.</p>")
go_button = gr.Button(value="Run extractor", variant="primary")
model_output_text_box = gr.Textbox(label="Extractor Output", elem_id="model_output_text_box")
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.click(fn=use_gemini, inputs=[pdf_file, key], outputs=[model_output_text_box])
@spaces.GPU
def use_openai(pdf_filepath, key):
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 = OAIExtractorConfig(prompt="Extract all text from the document.", model_name="gpt-4o", key=key)
result = oai_extractor.extract(content, config)
return result
with gr.Blocks(title="PDF data extraction with OpenAI & Indexify") as openai_demo:
gr.HTML("<h1 style='text-align: center'>PDF data extraction with OpenAI & <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/multimodal_openai.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 = gr.File(type="filepath")
gr.HTML("<p><b>Step 2:</b> Enter your API key.</p>")
key = gr.Textbox(info="Please enter your OPENAI_API_KEY", label="Key:")
with gr.Column():
gr.HTML("<p><b>Step 3:</b> Run the extractor.</p>")
go_button = gr.Button(value="Run extractor", variant="primary")
model_output_text_box = gr.Textbox(label="Extractor Output", elem_id="model_output_text_box")
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.click(fn=use_openai, inputs=[pdf_file, key], outputs=[model_output_text_box])
demo = gr.TabbedInterface([marker_demo, pdf_demo, gemini_demo, openai_demo], ["Marker Extractor", "PDF Extractor", "Gemini Extractor", "OpenAI Extractor"], theme=gr.themes.Soft())
demo.queue()
demo.launch()