Spaces:
Runtime error
Runtime error
import gradio as gr | |
from newspaper import Config, Article | |
import torch | |
from transformers import pipeline | |
summarizer = pipeline("summarization", model="achimoraites/flan-t5-base-samsum") | |
def summarize(text): | |
return summarizer(text, max_length=128, min_length=30)[0]['summary_text'] | |
def summarize_article(url): | |
config = Config() | |
config.browser_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" | |
config.request_timeout = 6 | |
article = Article(url, config=config) | |
summary = '' | |
try: | |
article.download() | |
article.parse() | |
summary = summarize(article.text) | |
except Exception as e: | |
return f"Failed to summarize. Error: {e}" | |
return summary | |
iface = gr.Interface(fn=summarize_article, | |
live=False, | |
capture_session=True, | |
inputs=gr.inputs.Textbox(lines=1, label="Page URL"), | |
outputs="text", | |
title="Page Summarizer", | |
) | |
iface.launch(inline = False) |