File size: 1,103 Bytes
225fbae
 
 
 
 
481c13a
225fbae
 
 
 
 
 
 
 
 
 
 
 
 
 
2dbf8a4
225fbae
 
 
 
 
 
2347b86
225fbae
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)