Spaces:
Runtime error
Runtime error
Commit
•
199825b
1
Parent(s):
80a2499
update
Browse files
app.py
CHANGED
@@ -13,23 +13,44 @@ newsapi = NewsApiClient(api_key=HF_TOKEN)
|
|
13 |
|
14 |
classifier = pipeline(model="cardiffnlp/twitter-roberta-base-sentiment")
|
15 |
today = str(date.today())
|
|
|
|
|
16 |
all_articles = newsapi.get_everything(sources='the-times-of-india',
|
17 |
domains='timesofindia.indiatimes.com',
|
18 |
from_param=today,
|
19 |
to=today,
|
20 |
language='en',
|
21 |
sort_by='relevancy',)
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
#Driver
|
25 |
def inference(newssource): #, date):
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
dictnews = { 'description' : [entry['description'] for entry in all_articles['articles']],
|
34 |
'content' : [entry['content'] for entry in all_articles['articles']],
|
35 |
'url' : [entry['url'] for entry in all_articles['articles']],
|
|
|
13 |
|
14 |
classifier = pipeline(model="cardiffnlp/twitter-roberta-base-sentiment")
|
15 |
today = str(date.today())
|
16 |
+
|
17 |
+
#times of india
|
18 |
all_articles = newsapi.get_everything(sources='the-times-of-india',
|
19 |
domains='timesofindia.indiatimes.com',
|
20 |
from_param=today,
|
21 |
to=today,
|
22 |
language='en',
|
23 |
sort_by='relevancy',)
|
24 |
+
sentiment_toi = ['Negative' if classifier(entry['content'])[0]['label'] == 'LABEL_0' else 'Neutral' if classifier(entry['content'])[0]['label'] == 'LABEL_1' else 'Positive' for entry in all_articles['articles']]
|
25 |
+
|
26 |
+
#the hindu
|
27 |
+
all_articles = newsapi.get_everything(sources='the-hindu',
|
28 |
+
domains='thehindu.com',
|
29 |
+
from_param=today,
|
30 |
+
to=today,
|
31 |
+
language='en',
|
32 |
+
sort_by='relevancy',)
|
33 |
+
sentiment_hindu = ['Negative' if classifier(entry['content'])[0]['label'] == 'LABEL_0' else 'Neutral' if classifier(entry['content'])[0]['label'] == 'LABEL_1' else 'Positive' for entry in all_articles['articles']]
|
34 |
+
|
35 |
+
#google news
|
36 |
+
all_articles = newsapi.get_everything(sources='google-news-in',
|
37 |
+
domains='news.google.com',
|
38 |
+
from_param=today,
|
39 |
+
to=today,
|
40 |
+
language='en',
|
41 |
+
sort_by='relevancy',)
|
42 |
+
sentiment_google = ['Negative' if classifier(entry['content'])[0]['label'] == 'LABEL_0' else 'Neutral' if classifier(entry['content'])[0]['label'] == 'LABEL_1' else 'Positive' for entry in all_articles['articles']]
|
43 |
|
44 |
#Driver
|
45 |
def inference(newssource): #, date):
|
46 |
+
|
47 |
+
if newssource == "Times Of India":
|
48 |
+
sentiment = sentiment_toi
|
49 |
+
elif newssource == "The Hindu":
|
50 |
+
sentiment = sentiment_hindu
|
51 |
+
elif newssource == "Google News":
|
52 |
+
sentiment = sentiment_google
|
53 |
+
|
54 |
dictnews = { 'description' : [entry['description'] for entry in all_articles['articles']],
|
55 |
'content' : [entry['content'] for entry in all_articles['articles']],
|
56 |
'url' : [entry['url'] for entry in all_articles['articles']],
|