Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Versi贸n 1.0: Interfaz Modular con Gradio
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import config
|
| 4 |
+
from core import PDFEngine
|
| 5 |
+
|
| 6 |
+
# Instanciamos el motor (Inyecci贸n simple)
|
| 7 |
+
engine = PDFEngine()
|
| 8 |
+
|
| 9 |
+
def interface_merge(files):
|
| 10 |
+
if not files:
|
| 11 |
+
return None
|
| 12 |
+
# Gradio pasa objetos 'namedtuple' o rutas dependiendo de la config.
|
| 13 |
+
# Asumimos que files es una lista de rutas de archivo.
|
| 14 |
+
return engine.merge_pdfs(files)
|
| 15 |
+
|
| 16 |
+
def interface_split(file):
|
| 17 |
+
if not file:
|
| 18 |
+
return None
|
| 19 |
+
return engine.split_pdf(file)
|
| 20 |
+
|
| 21 |
+
def interface_protect(file, password):
|
| 22 |
+
if not file or not password:
|
| 23 |
+
return None
|
| 24 |
+
return engine.protect_pdf(file, password)
|
| 25 |
+
|
| 26 |
+
# Construcci贸n de la UI
|
| 27 |
+
with gr.Blocks(title=config.APP_TITLE, theme=gr.themes.Soft()) as demo:
|
| 28 |
+
gr.Markdown(f"# {config.APP_TITLE}")
|
| 29 |
+
gr.Markdown(config.APP_DESCRIPTION)
|
| 30 |
+
|
| 31 |
+
with gr.Tabs():
|
| 32 |
+
# --- TAB: UNIR PDF ---
|
| 33 |
+
with gr.TabItem("Unir PDF"):
|
| 34 |
+
gr.Markdown(config.TXT_MERGE)
|
| 35 |
+
with gr.Row():
|
| 36 |
+
with gr.Column():
|
| 37 |
+
merge_input = gr.File(
|
| 38 |
+
file_count="multiple",
|
| 39 |
+
file_types=[".pdf"],
|
| 40 |
+
label="Sube tus PDFs (en orden)"
|
| 41 |
+
)
|
| 42 |
+
merge_btn = gr.Button("Unir Archivos", variant="primary")
|
| 43 |
+
with gr.Column():
|
| 44 |
+
merge_output = gr.File(label="PDF Unido")
|
| 45 |
+
|
| 46 |
+
merge_btn.click(
|
| 47 |
+
fn=interface_merge,
|
| 48 |
+
inputs=merge_input,
|
| 49 |
+
outputs=merge_output
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
# --- TAB: DIVIDIR PDF ---
|
| 53 |
+
with gr.TabItem("Dividir PDF"):
|
| 54 |
+
gr.Markdown(config.TXT_SPLIT)
|
| 55 |
+
with gr.Row():
|
| 56 |
+
with gr.Column():
|
| 57 |
+
split_input = gr.File(
|
| 58 |
+
file_count="single",
|
| 59 |
+
file_types=[".pdf"],
|
| 60 |
+
label="Sube tu PDF"
|
| 61 |
+
)
|
| 62 |
+
split_btn = gr.Button("Dividir en P谩ginas", variant="primary")
|
| 63 |
+
with gr.Column():
|
| 64 |
+
# Gradio maneja listas de archivos como salida autom谩ticamente
|
| 65 |
+
split_output = gr.File(label="P谩ginas Extra铆das", file_count="multiple")
|
| 66 |
+
|
| 67 |
+
split_btn.click(
|
| 68 |
+
fn=interface_split,
|
| 69 |
+
inputs=split_input,
|
| 70 |
+
outputs=split_output
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# --- TAB: PROTEGER PDF ---
|
| 74 |
+
with gr.TabItem("Proteger PDF"):
|
| 75 |
+
gr.Markdown(config.TXT_PROTECT)
|
| 76 |
+
with gr.Row():
|
| 77 |
+
with gr.Column():
|
| 78 |
+
protect_input = gr.File(label="PDF a proteger")
|
| 79 |
+
pass_input = gr.Textbox(label="Contrase帽a", type="password")
|
| 80 |
+
protect_btn = gr.Button("Encriptar", variant="primary")
|
| 81 |
+
with gr.Column():
|
| 82 |
+
protect_output = gr.File(label="PDF Encriptado")
|
| 83 |
+
|
| 84 |
+
protect_btn.click(
|
| 85 |
+
fn=interface_protect,
|
| 86 |
+
inputs=[protect_input, pass_input],
|
| 87 |
+
outputs=protect_output
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
demo.launch()
|