Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -56,23 +56,34 @@ def convert(pdf_file):
|
|
56 |
doc = original_doc
|
57 |
|
58 |
markdown = extract_text_markdown(doc)
|
59 |
-
metadata = {} #
|
60 |
return markdown, metadata
|
61 |
|
62 |
-
# Gradio
|
63 |
with gr.Blocks(title="Extractor PDF a Markdown") as demo:
|
64 |
gr.Markdown("### PDF → Markdown con imágenes como enlaces y botón de copiar")
|
65 |
|
66 |
pdf_input = gr.File(label="Sube tu PDF", type="filepath")
|
67 |
-
markdown_output = gr.Textbox(label="Markdown generado", lines=25
|
68 |
metadata_output = gr.JSON(label="Metadata")
|
69 |
|
|
|
|
|
70 |
with gr.Row():
|
71 |
convert_btn = gr.Button("Convertir PDF")
|
72 |
-
copy_btn = gr.
|
73 |
-
<button onclick="navigator.clipboard.writeText(document.getElementById('md_output').value)">📋 Copiar Markdown</button>
|
74 |
-
""")
|
75 |
|
76 |
convert_btn.click(fn=convert, inputs=pdf_input, outputs=[markdown_output, metadata_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
demo.launch()
|
|
|
56 |
doc = original_doc
|
57 |
|
58 |
markdown = extract_text_markdown(doc)
|
59 |
+
metadata = {} # Puedes rellenar si quieres
|
60 |
return markdown, metadata
|
61 |
|
62 |
+
# Gradio Blocks UI
|
63 |
with gr.Blocks(title="Extractor PDF a Markdown") as demo:
|
64 |
gr.Markdown("### PDF → Markdown con imágenes como enlaces y botón de copiar")
|
65 |
|
66 |
pdf_input = gr.File(label="Sube tu PDF", type="filepath")
|
67 |
+
markdown_output = gr.Textbox(label="Markdown generado", lines=25)
|
68 |
metadata_output = gr.JSON(label="Metadata")
|
69 |
|
70 |
+
hidden_textarea = gr.Textbox(visible=False)
|
71 |
+
|
72 |
with gr.Row():
|
73 |
convert_btn = gr.Button("Convertir PDF")
|
74 |
+
copy_btn = gr.Button("📋 Copiar Markdown")
|
|
|
|
|
75 |
|
76 |
convert_btn.click(fn=convert, inputs=pdf_input, outputs=[markdown_output, metadata_output])
|
77 |
+
# Al hacer clic en copiar, movemos el contenido visible al invisible y ejecutamos JS
|
78 |
+
copy_btn.click(lambda text: text, inputs=markdown_output, outputs=hidden_textarea).then(
|
79 |
+
None,
|
80 |
+
_js="""
|
81 |
+
() => {
|
82 |
+
const text = document.querySelectorAll("textarea")[1].value;
|
83 |
+
navigator.clipboard.writeText(text);
|
84 |
+
alert("¡Markdown copiado al portapapeles!");
|
85 |
+
}
|
86 |
+
"""
|
87 |
+
)
|
88 |
|
89 |
demo.launch()
|