add fancy.css
Browse files
app.py
CHANGED
|
@@ -4,11 +4,15 @@ from typing import List
|
|
| 4 |
import gradio as gr
|
| 5 |
from PyPDF2 import PdfReader, PdfWriter
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Maximum upload size
|
| 8 |
MAX_SIZE_BYTES = 1 * 1024 * 1024 * 1024 # 1 GB
|
| 9 |
|
| 10 |
# Note: Uploaded PDFs are processed in-memory and not stored on the server.
|
| 11 |
-
# This is a
|
| 12 |
|
| 13 |
def parse_page_ranges(ranges: str, num_pages: int) -> List[int]:
|
| 14 |
"""
|
|
@@ -28,7 +32,6 @@ def parse_page_ranges(ranges: str, num_pages: int) -> List[int]:
|
|
| 28 |
pages.add(p - 1)
|
| 29 |
return sorted(pages)
|
| 30 |
|
| 31 |
-
|
| 32 |
def split_pdf(file, page_ranges: str):
|
| 33 |
# Validate file size
|
| 34 |
file_size = os.path.getsize(file.name)
|
|
@@ -56,13 +59,9 @@ def split_pdf(file, page_ranges: str):
|
|
| 56 |
return out_path, None
|
| 57 |
|
| 58 |
# Build Gradio interface
|
| 59 |
-
with gr.Blocks(css=
|
| 60 |
-
#header {text-align: center; margin-bottom: 20px;}
|
| 61 |
-
.input-row {display: flex; gap: 10px; margin-bottom: 20px;}
|
| 62 |
-
.button-row {text-align: center; margin-top: 20px;}
|
| 63 |
-
""") as demo:
|
| 64 |
# Header
|
| 65 |
-
gr.HTML("<h1 id='header'
|
| 66 |
gr.Markdown("**Free & Quick Solution**: Uploaded PDFs are processed but not stored. Ideal for lazy splitting without installing anything.")
|
| 67 |
gr.Markdown("Upload a PDF (up to 1 GB) and extract specific pages using ranges like `1-3,5,7-9`.")
|
| 68 |
|
|
@@ -84,10 +83,12 @@ with gr.Blocks(css="""
|
|
| 84 |
return None, error, True
|
| 85 |
return out_path, "", False
|
| 86 |
|
| 87 |
-
split_button.click(
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
|
| 92 |
# Hide error box when no error
|
| 93 |
error_text.change(lambda msg: msg != "", inputs=error_text, outputs=error_text)
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from PyPDF2 import PdfReader, PdfWriter
|
| 6 |
|
| 7 |
+
# Load custom CSS
|
| 8 |
+
with open(os.path.join(os.path.dirname(__file__), "fancy.css")) as f:
|
| 9 |
+
custom_css = f.read()
|
| 10 |
+
|
| 11 |
# Maximum upload size
|
| 12 |
MAX_SIZE_BYTES = 1 * 1024 * 1024 * 1024 # 1 GB
|
| 13 |
|
| 14 |
# Note: Uploaded PDFs are processed in-memory and not stored on the server.
|
| 15 |
+
# This is a quick solution for splitting PDFs without any external storage.
|
| 16 |
|
| 17 |
def parse_page_ranges(ranges: str, num_pages: int) -> List[int]:
|
| 18 |
"""
|
|
|
|
| 32 |
pages.add(p - 1)
|
| 33 |
return sorted(pages)
|
| 34 |
|
|
|
|
| 35 |
def split_pdf(file, page_ranges: str):
|
| 36 |
# Validate file size
|
| 37 |
file_size = os.path.getsize(file.name)
|
|
|
|
| 59 |
return out_path, None
|
| 60 |
|
| 61 |
# Build Gradio interface
|
| 62 |
+
with gr.Blocks(css=custom_css) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# Header
|
| 64 |
+
gr.HTML("<h1 id='header'>PDF Splitter</h1>")
|
| 65 |
gr.Markdown("**Free & Quick Solution**: Uploaded PDFs are processed but not stored. Ideal for lazy splitting without installing anything.")
|
| 66 |
gr.Markdown("Upload a PDF (up to 1 GB) and extract specific pages using ranges like `1-3,5,7-9`.")
|
| 67 |
|
|
|
|
| 83 |
return None, error, True
|
| 84 |
return out_path, "", False
|
| 85 |
|
| 86 |
+
split_button.click(
|
| 87 |
+
fn=run_split,
|
| 88 |
+
inputs=[pdf_input, page_input],
|
| 89 |
+
outputs=[output_file, error_text, error_text],
|
| 90 |
+
api_name="split_pdf"
|
| 91 |
+
)
|
| 92 |
|
| 93 |
# Hide error box when no error
|
| 94 |
error_text.change(lambda msg: msg != "", inputs=error_text, outputs=error_text)
|