Spaces:
Runtime error
Runtime error
Commit
·
23b410a
1
Parent(s):
f0f3661
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,35 @@ import gradio as gr
|
|
2 |
import json
|
3 |
import requests
|
4 |
from newspaper import Article
|
|
|
5 |
|
6 |
|
7 |
def get_news(search):
|
8 |
-
article_texts=[]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import json
|
3 |
import requests
|
4 |
from newspaper import Article
|
5 |
+
from gradio.mix import Parallel, Series
|
6 |
|
7 |
|
8 |
def get_news(search):
|
9 |
+
article_texts=[]
|
10 |
+
url = "https://free-news.p.rapidapi.com/v1/search"
|
11 |
+
querystring = {"q":search,"lang":"en", "page":1, "page_size":5}
|
12 |
+
headers = {'x-rapidapi-host': "free-news.p.rapidapi.com",'x-rapidapi-key': "375ffbaab0mshb442ffb69d6f025p117ba0jsn01e8146148e3"}
|
13 |
+
response = requests.request("GET", url, headers=headers, params=querystring)
|
14 |
+
response_dict = json.loads(response.text)
|
15 |
+
links = [response_dict['articles'][i]['link'] for i in range(len(response_dict['articles']))]
|
16 |
+
news_article = Article(link[0], language='en')
|
17 |
+
news_article.download()
|
18 |
+
news_article.parse()
|
19 |
+
article_texts.append(news_article.text)
|
20 |
+
return article_texts[0]
|
21 |
|
22 |
+
extractor = gr.Interface(get_news, 'text', 'text')
|
23 |
+
summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")
|
24 |
+
|
25 |
+
|
26 |
+
iface = Series(extractor, summarizer,
|
27 |
+
inputs = gr.inputs.Textbox(
|
28 |
+
lines = 2,
|
29 |
+
label = 'Enter URL below'
|
30 |
+
),
|
31 |
+
outputs = 'text',
|
32 |
+
title = 'News Summarizer',
|
33 |
+
theme = 'grass',
|
34 |
+
layout = 'horizontal')
|
35 |
+
|
36 |
+
iface.launch()
|