File size: 1,465 Bytes
1389cb3
 
 
 
 
 
001d877
 
 
1389cb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from newspaper import Article
from newspaper import Config
from datetime import datetime
import nltk

nltk.download("punkt")

import gradio as gr


def summarize(url):
    USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:96.0) Gecko/20100101 Firefox/96.0"
    config = Config()
    config.browser_user_agent = USER_AGENT
    config.request_timeout = 10

    article = Article(url, config=config)
    try:
        article.download()
        article.parse()
        article.nlp()
        print("==========================", datetime.utcnow(), url, article.summary, sep="\n")
    except Exception as e:
        return f"Failed to summarize. Error: {e}"
    return article.summary


sample_url = [
    [
        "https://www.technologyreview.com/2021/07/22/1029973/deepmind-alphafold-protein-folding-biology-disease-drugs-proteome/"
    ],
    [
        "https://www.technologyreview.com/2021/07/21/1029860/disability-rights-employment-discrimination-ai-hiring/"
    ],
    [
        "https://www.technologyreview.com/2021/07/09/1028140/ai-voice-actors-sound-human/"
    ],
]


iface = gr.Interface(
    fn=summarize,
    inputs=gr.inputs.Textbox(lines=2, label="URL"),
    outputs="text",
    title="News Summarizer",
    theme="huggingface",
    description="Fast and simple article summarizer. [Install iOS shortcut](https://www.icloud.com/shortcuts/a7e092bccae34551b24724798f195590) to use from your iPhone",
    examples=sample_url,
)
iface.launch()