Spaces:
Sleeping
Sleeping
import gradio as gr | |
import nltk | |
nltk.download('punkt') | |
nltk.download('averaged_perceptron_tagger') | |
nltk.download('brown') | |
from transformers import pipeline | |
from newspaper import Article | |
from textblob import TextBlob | |
def Article_outline(url): #可輸入文章網址,提取該文章的標題、內文、摘要和進行情感分析 | |
article = Article(url) | |
article.download() | |
article.parse() | |
summerizer = pipeline("summarization") | |
blob = TextBlob(article.text) | |
title="" | |
title = "文章標題:" + article.title | |
txt="" | |
txt = "內文:" + article.text | |
sum="" | |
sum = "摘要:" + str(summerizer(article.text)) | |
txtsen='' | |
if blob.sentiment.polarity > 0: | |
txtsen = "本文偏向正向情緒" | |
elif blob.sentiment.polarity < 0: | |
txtsen = "本文偏向負向情緒" | |
result=title + txt + sum + txtsen | |
return result | |
demo = gr.Interface(fn=Article_outline, inputs="text", outputs="text") | |
demo.launch() |