Spaces:
Running
Running
Commit
·
1389cb3
1
Parent(s):
001d877
initial commit
Browse files
app.py
CHANGED
@@ -1,16 +1,50 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
import numpy as np
|
4 |
import gradio as gr
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from newspaper import Article
|
2 |
+
from newspaper import Config
|
3 |
+
from datetime import datetime
|
4 |
+
import nltk
|
5 |
+
|
6 |
+
nltk.download("punkt")
|
7 |
|
|
|
8 |
import gradio as gr
|
9 |
|
10 |
+
|
11 |
+
def summarize(url):
|
12 |
+
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:96.0) Gecko/20100101 Firefox/96.0"
|
13 |
+
config = Config()
|
14 |
+
config.browser_user_agent = USER_AGENT
|
15 |
+
config.request_timeout = 10
|
16 |
+
|
17 |
+
article = Article(url, config=config)
|
18 |
+
try:
|
19 |
+
article.download()
|
20 |
+
article.parse()
|
21 |
+
article.nlp()
|
22 |
+
print("==========================", datetime.utcnow(), url, article.summary, sep="\n")
|
23 |
+
except Exception as e:
|
24 |
+
return f"Failed to summarize. Error: {e}"
|
25 |
+
return article.summary
|
26 |
+
|
27 |
+
|
28 |
+
sample_url = [
|
29 |
+
[
|
30 |
+
"https://www.technologyreview.com/2021/07/22/1029973/deepmind-alphafold-protein-folding-biology-disease-drugs-proteome/"
|
31 |
+
],
|
32 |
+
[
|
33 |
+
"https://www.technologyreview.com/2021/07/21/1029860/disability-rights-employment-discrimination-ai-hiring/"
|
34 |
+
],
|
35 |
+
[
|
36 |
+
"https://www.technologyreview.com/2021/07/09/1028140/ai-voice-actors-sound-human/"
|
37 |
+
],
|
38 |
+
]
|
39 |
+
|
40 |
+
|
41 |
+
iface = gr.Interface(
|
42 |
+
fn=summarize,
|
43 |
+
inputs=gr.inputs.Textbox(lines=2, label="URL"),
|
44 |
+
outputs="text",
|
45 |
+
title="News Summarizer",
|
46 |
+
theme="huggingface",
|
47 |
+
description="Fast and simple article summarizer. [Install iOS shortcut](https://www.icloud.com/shortcuts/a7e092bccae34551b24724798f195590) to use from your iPhone",
|
48 |
+
examples=sample_url,
|
49 |
+
)
|
50 |
+
iface.launch()
|