Spaces:
Runtime error
Runtime error
Commit
•
4252e62
1
Parent(s):
ee98c85
update
Browse files
app.py
CHANGED
@@ -17,32 +17,33 @@ today = str(date.today())
|
|
17 |
print(f"HF_TOKEN is - {HF_TOKEN}")
|
18 |
|
19 |
#times of india
|
20 |
-
|
21 |
domains='timesofindia.indiatimes.com',
|
22 |
from_param=today,
|
23 |
to=today,
|
24 |
language='en',
|
25 |
sort_by='relevancy',)
|
26 |
-
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
|
27 |
print(f"sentiment_toi length is {len(sentiment_toi)}")
|
|
|
28 |
#the hindu
|
29 |
-
|
30 |
domains='thehindu.com',
|
31 |
from_param=today,
|
32 |
to=today,
|
33 |
language='en',
|
34 |
sort_by='relevancy',)
|
35 |
-
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
|
36 |
-
print(f"
|
37 |
|
38 |
#google news
|
39 |
-
|
40 |
domains='news.google.com',
|
41 |
from_param=today,
|
42 |
to=today,
|
43 |
language='en',
|
44 |
sort_by='relevancy',)
|
45 |
-
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
|
46 |
print(f"sentiment_google length is {len(sentiment_google)}")
|
47 |
|
48 |
#Driver
|
@@ -50,10 +51,13 @@ def inference(newssource): #, date):
|
|
50 |
|
51 |
if newssource == "Times Of India":
|
52 |
sentiment = sentiment_toi
|
|
|
53 |
elif newssource == "The Hindu":
|
54 |
sentiment = sentiment_hindu
|
|
|
55 |
elif newssource == "Google News":
|
56 |
sentiment = sentiment_google
|
|
|
57 |
|
58 |
description = [entry['description'] for entry in all_articles['articles']]
|
59 |
content = [entry['content'] for entry in all_articles['articles']]
|
@@ -66,12 +70,13 @@ def inference(newssource): #, date):
|
|
66 |
print(f"urlToImage length is {len(urlToImage)}")
|
67 |
print(f"sentiment length is {len(sentiment)}")
|
68 |
|
69 |
-
dictnews = { 'description' :
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
75 |
df = pd.DataFrame.from_dict(dictnews)
|
76 |
html_out = "<img src= " + dictnews['urlToImage'][0] + ">"
|
77 |
return df, html_out
|
|
|
17 |
print(f"HF_TOKEN is - {HF_TOKEN}")
|
18 |
|
19 |
#times of india
|
20 |
+
all_articles_toi = newsapi.get_everything(sources='the-times-of-india',
|
21 |
domains='timesofindia.indiatimes.com',
|
22 |
from_param=today,
|
23 |
to=today,
|
24 |
language='en',
|
25 |
sort_by='relevancy',)
|
26 |
+
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_toi['articles']]
|
27 |
print(f"sentiment_toi length is {len(sentiment_toi)}")
|
28 |
+
|
29 |
#the hindu
|
30 |
+
all_articles_hindu = newsapi.get_everything(sources='the-hindu',
|
31 |
domains='thehindu.com',
|
32 |
from_param=today,
|
33 |
to=today,
|
34 |
language='en',
|
35 |
sort_by='relevancy',)
|
36 |
+
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_hindu['articles']]
|
37 |
+
print(f"sentiment_hindu length is {len(sentiment_hindu)}")
|
38 |
|
39 |
#google news
|
40 |
+
all_articles_google = newsapi.get_everything(sources='google-news-in',
|
41 |
domains='news.google.com',
|
42 |
from_param=today,
|
43 |
to=today,
|
44 |
language='en',
|
45 |
sort_by='relevancy',)
|
46 |
+
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_google['articles']]
|
47 |
print(f"sentiment_google length is {len(sentiment_google)}")
|
48 |
|
49 |
#Driver
|
|
|
51 |
|
52 |
if newssource == "Times Of India":
|
53 |
sentiment = sentiment_toi
|
54 |
+
all_articles = all_articles_toi
|
55 |
elif newssource == "The Hindu":
|
56 |
sentiment = sentiment_hindu
|
57 |
+
all_articles = all_articles_hindu
|
58 |
elif newssource == "Google News":
|
59 |
sentiment = sentiment_google
|
60 |
+
all_articles = all_articles_google
|
61 |
|
62 |
description = [entry['description'] for entry in all_articles['articles']]
|
63 |
content = [entry['content'] for entry in all_articles['articles']]
|
|
|
70 |
print(f"urlToImage length is {len(urlToImage)}")
|
71 |
print(f"sentiment length is {len(sentiment)}")
|
72 |
|
73 |
+
dictnews = { 'description' : description, 'content' : content, 'url' : url, 'urlToImage' : urlToImage, 'sentiment' : sentiment,}
|
74 |
+
#dictnews = { 'description' : [entry['description'] for entry in all_articles['articles']],
|
75 |
+
# 'content' : [entry['content'] for entry in all_articles['articles']],
|
76 |
+
# 'url' : [entry['url'] for entry in all_articles['articles']],
|
77 |
+
# 'urlToImage' : [entry['urlToImage'] for entry in all_articles['articles']],
|
78 |
+
# 'sentiment' : sentiment,
|
79 |
+
# }
|
80 |
df = pd.DataFrame.from_dict(dictnews)
|
81 |
html_out = "<img src= " + dictnews['urlToImage'][0] + ">"
|
82 |
return df, html_out
|