Spaces:
Sleeping
Sleeping
File size: 1,655 Bytes
33b80e1 aa93542 3ab32c0 0d7e7bf 33b80e1 3ab32c0 33b80e1 447cde6 0d7e7bf 33b80e1 aa93542 33b80e1 aa93542 33b80e1 aa93542 33b80e1 aa93542 33b80e1 aa93542 33b80e1 aa93542 33b80e1 aa93542 33b80e1 0d7e7bf | 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 | import gradio as gr
from gradio_pdf import PDF
from services.extraction_service import extract_tables
from config import SERVER_NAME, SERVER_PORT, IN_SPACES
with gr.Blocks(title="Tables Extractor", theme=gr.themes.Soft()) as demo:
gr.Markdown(
"""
# Table Extraction
Upload up to **15 text-based PDFs** and extract tables to structured JSON.
The UI renders detected tables; you can also download JSON + metrics.
"""
)
with gr.Row():
inp = gr.File(
file_types=[".pdf"],
label="Upload PDFs",
type="filepath",
file_count="multiple"
)
with gr.Row():
run_btn = gr.Button("Extract Tables", variant="primary")
with gr.Row():
status = gr.Markdown()
with gr.Row():
with gr.Column(scale=1):
pdf_preview = PDF(
label="PDF Preview (First Uploaded)",
interactive=True,
height=400
)
with gr.Column(scale=1):
gallery = gr.Gallery(
label="Detected Table Previews",
height=400,
columns=2,
object_fit="contain"
)
with gr.Row():
downloads = gr.Files(label="Download (tables.json, metrics.json)")
with gr.Row():
html_view = gr.HTML()
run_btn.click(
fn=extract_tables,
inputs=[inp],
outputs=[status, downloads, gallery, html_view, pdf_preview]
)
if __name__ == "__main__":
demo.launch(
server_name=SERVER_NAME,
server_port=SERVER_PORT,
debug=not IN_SPACES
)
|