File size: 1,408 Bytes
f0f3661
 
 
 
23b410a
f0f3661
 
 
765e2c6
23b410a
 
 
 
 
 
4ecc590
23b410a
 
765e2c6
 
f0f3661
23b410a
 
 
 
 
 
c142043
23b410a
 
e077c15
04e2040
 
52fdae8
23b410a
e83c79d
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
import gradio as gr
import json
import requests
from newspaper import Article
from gradio.mix import Parallel, Series


def get_news(search):
    #article_texts=[]
    url = "https://free-news.p.rapidapi.com/v1/search"
    querystring = {"q":search,"lang":"en", "page":1, "page_size":5}
    headers = {'x-rapidapi-host': "free-news.p.rapidapi.com",'x-rapidapi-key': "375ffbaab0mshb442ffb69d6f025p117ba0jsn01e8146148e3"}
    response = requests.request("GET", url, headers=headers, params=querystring)
    response_dict = json.loads(response.text)
    links = [response_dict['articles'][i]['link'] for i in range(len(response_dict['articles']))]
    news_article = Article(links[0], language='en')
    news_article.download()
    news_article.parse()
    #article_texts.append(news_article.text)
    return news_article.text

extractor = gr.Interface(get_news, 'text', 'text')
summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")


iface = Series(extractor, summarizer, 
  inputs = gr.inputs.Textbox(
      label = 'Type in a topic or your favorite celebrity name to fetch news on that topic/celebrity name'
  ),
  outputs = 'text',
  title = 'Instant short News app with Gradio',
  theme = 'peach',
  layout = 'horizontal',
  description = 'This app fetches a latest news article from the Internet based on the given search and displays a summary of that article')

iface.launch(debug=True)