Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from newspaper import Article
|
| 3 |
|
| 4 |
-
def
|
| 5 |
try:
|
| 6 |
articulo = Article(url, language='es')
|
| 7 |
articulo.download()
|
| 8 |
articulo.parse()
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
except Exception as e:
|
| 11 |
-
return f"[Error al extraer texto]: {str(e)}"
|
| 12 |
|
| 13 |
with gr.Blocks() as demo:
|
| 14 |
-
gr.Markdown("## Extractor de Texto de Noticias 📰")
|
| 15 |
-
gr.Markdown("Pega el enlace de una noticia para extraer su contenido
|
| 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,
|
| 22 |
interactive=False,
|
| 23 |
elem_id="texto_extraido"
|
| 24 |
)
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
| 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');
|
|
@@ -40,6 +43,10 @@ with gr.Blocks() as demo:
|
|
| 40 |
">📋 Copiar texto</button>
|
| 41 |
""")
|
| 42 |
|
| 43 |
-
btn_extraer.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from newspaper import Article
|
| 3 |
|
| 4 |
+
def extraer_info(url):
|
| 5 |
try:
|
| 6 |
articulo = Article(url, language='es')
|
| 7 |
articulo.download()
|
| 8 |
articulo.parse()
|
| 9 |
+
titulo_y_texto = f"{articulo.title}\n\n{articulo.text}"
|
| 10 |
+
imagen_url = articulo.top_image # Imagen principal
|
| 11 |
+
return titulo_y_texto, imagen_url
|
| 12 |
except Exception as e:
|
| 13 |
+
return f"[Error al extraer texto]: {str(e)}", None
|
| 14 |
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("## Extractor de Texto e Imagen de Noticias 📰🖼️")
|
| 17 |
+
gr.Markdown("Pega el enlace de una noticia para extraer su contenido y la imagen principal.")
|
| 18 |
|
| 19 |
url_input = gr.Textbox(label="URL de la noticia", placeholder="https://...")
|
| 20 |
|
| 21 |
texto_output = gr.Textbox(
|
| 22 |
+
label="Texto extraído (incluye título)",
|
| 23 |
+
lines=5,
|
| 24 |
interactive=False,
|
| 25 |
elem_id="texto_extraido"
|
| 26 |
)
|
| 27 |
|
| 28 |
+
imagen_output = gr.Image(label="Imagen principal", interactive=False)
|
| 29 |
+
|
| 30 |
+
btn_extraer = gr.Button("Extraer texto e imagen")
|
| 31 |
|
|
|
|
| 32 |
gr.HTML("""
|
| 33 |
<button id="btn_copiar" style="margin-top:10px;" onclick="
|
| 34 |
const txt = document.querySelector('#texto_extraido textarea');
|
|
|
|
| 43 |
">📋 Copiar texto</button>
|
| 44 |
""")
|
| 45 |
|
| 46 |
+
btn_extraer.click(
|
| 47 |
+
fn=extraer_info,
|
| 48 |
+
inputs=[url_input],
|
| 49 |
+
outputs=[texto_output, imagen_output]
|
| 50 |
+
)
|
| 51 |
|
| 52 |
demo.launch()
|