Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ def extraer_texto(url):
|
|
| 6 |
articulo = Article(url, language='es')
|
| 7 |
articulo.download()
|
| 8 |
articulo.parse()
|
| 9 |
-
return articulo.text
|
| 10 |
except Exception as e:
|
| 11 |
return f"[Error al extraer texto]: {str(e)}"
|
| 12 |
|
|
@@ -15,22 +15,27 @@ with gr.Blocks() as demo:
|
|
| 15 |
gr.Markdown("Pega el enlace de una noticia para extraer su contenido limpio.")
|
| 16 |
|
| 17 |
url_input = gr.Textbox(label="URL de la noticia", placeholder="https://...")
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
btn_extraer = gr.Button("Extraer texto")
|
| 23 |
|
| 24 |
-
# Botón HTML
|
| 25 |
gr.HTML("""
|
| 26 |
-
<button style="margin-top:10px;" onclick="
|
| 27 |
const txt = document.querySelector('#texto_extraido textarea');
|
|
|
|
| 28 |
if (txt) {
|
| 29 |
navigator.clipboard.writeText(txt.value).then(() => {
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
});
|
| 32 |
-
} else {
|
| 33 |
-
alert('No se encontró el campo de texto para copiar.');
|
| 34 |
}
|
| 35 |
">📋 Copiar texto</button>
|
| 36 |
""")
|
|
|
|
| 6 |
articulo = Article(url, language='es')
|
| 7 |
articulo.download()
|
| 8 |
articulo.parse()
|
| 9 |
+
return f"{articulo.title}\n\n{articulo.text}"
|
| 10 |
except Exception as e:
|
| 11 |
return f"[Error al extraer texto]: {str(e)}"
|
| 12 |
|
|
|
|
| 15 |
gr.Markdown("Pega el enlace de una noticia para extraer su contenido limpio.")
|
| 16 |
|
| 17 |
url_input = gr.Textbox(label="URL de la noticia", placeholder="https://...")
|
| 18 |
+
|
| 19 |
+
texto_output = gr.Textbox(
|
| 20 |
+
label="Texto extraído",
|
| 21 |
+
lines=5, # Puedes ajustar la cantidad de líneas visibles
|
| 22 |
+
interactive=False,
|
| 23 |
+
elem_id="texto_extraido"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
btn_extraer = gr.Button("Extraer texto")
|
| 27 |
|
| 28 |
+
# Botón HTML que copia el texto y muestra un ✔️ temporalmente
|
| 29 |
gr.HTML("""
|
| 30 |
+
<button id="btn_copiar" style="margin-top:10px;" onclick="
|
| 31 |
const txt = document.querySelector('#texto_extraido textarea');
|
| 32 |
+
const btn = document.getElementById('btn_copiar');
|
| 33 |
if (txt) {
|
| 34 |
navigator.clipboard.writeText(txt.value).then(() => {
|
| 35 |
+
const original = btn.innerHTML;
|
| 36 |
+
btn.innerHTML = '✔️ Copiado';
|
| 37 |
+
setTimeout(() => { btn.innerHTML = original; }, 2000);
|
| 38 |
});
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
">📋 Copiar texto</button>
|
| 41 |
""")
|