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)