Download app.py from ElAnon/textsum: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/ElAnon/textsum/resolve/main/app.py
- Command line
-
hf download hf://spaces/ElAnon/textsum/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ElAnon/textsum/resolve/main/app.py
1.3 kB
| from newspaper import Article | |
| from newspaper import Config | |
| import nltk | |
| nltk.download('punkt') | |
| from transformers import pipeline | |
| import gradio as gr | |
| from gradio.mix import Parallel, Series | |
| def auto_link(url): | |
| USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0' | |
| configuration = Config() | |
| configuration.browser_user_agent = USER_AGENT | |
| configuration.request_timeout = 10 | |
| abstract = Article(url, config =configuration) | |
| abstract.download() | |
| abstract.parse() | |
| text = abstract.text | |
| return text | |
| extract = gr.Interface(auto_link, 'text', 'text') | |
| abstractive_summarization = gr.Interface.load("huggingface/facebook/bart-large-cnn") | |
| example_urls = [['https://www.ibm.com/cloud/learn/machine-learning/'], | |
| ['https://www.cnn.com/2021/11/24/us/arctic-ocean-early-warming-climate/index.html/'], | |
| ['https://www.britannica.com/topic/Pyramids-of-Giza']] | |
| title = ''' | |
| summarizeer | |
| ''' | |
| UI_summarizer = Series(extract, abstractive_summarization, inputs = gr.inputs.Textbox (lines = 2, label = 'URL'), | |
| outputs = 'text', title = 'Summarization', theme = 'huggingface', description = title, | |
| examples= example_urls) | |
| UI_summarizer.launch(inline = False) | |