Spaces:
Runtime error
Runtime error
Commit
•
132ce6b
1
Parent(s):
a6d76f1
update
Browse files
app.py
CHANGED
@@ -17,6 +17,12 @@ today = str(date.today())
|
|
17 |
print("******** Outside Inference function ********")
|
18 |
print(f"HF_TOKEN is - {HF_TOKEN}")
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
#times of india
|
21 |
all_articles_toi = newsapi.get_everything(sources='the-times-of-india',
|
22 |
domains= 'http://timesofindia.indiatimes.com', #'timesofindia.indiatimes.com',
|
@@ -28,27 +34,6 @@ sentiment_toi = ['Negative' if classifier(entry['content'])[0]['label'] == 'LABE
|
|
28 |
print(f"sentiment_toi length is {len(sentiment_toi)}")
|
29 |
print(f"all_articles_toi length is {len(all_articles_toi['articles'])}")
|
30 |
|
31 |
-
#the hindu
|
32 |
-
all_articles_hindu = newsapi.get_everything(sources='the-hindu',
|
33 |
-
domains= 'http://www.thehindu.com', #'thehindu.com',
|
34 |
-
from_param=today,
|
35 |
-
to=today,
|
36 |
-
language='en',
|
37 |
-
sort_by='relevancy',)
|
38 |
-
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']]
|
39 |
-
print(f"sentiment_hindu length is {len(sentiment_hindu)}")
|
40 |
-
print(f"all_articles_hindu length is {len(all_articles_hindu['articles'])}")
|
41 |
-
|
42 |
-
#google news
|
43 |
-
all_articles_google = newsapi.get_everything(sources='google-news-in',
|
44 |
-
domains = 'https://news.google.com', #'news.google.com',
|
45 |
-
from_param=today,
|
46 |
-
to=today,
|
47 |
-
language='en',
|
48 |
-
sort_by='relevancy',)
|
49 |
-
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']]
|
50 |
-
print(f"sentiment_google length is {len(sentiment_google)}")
|
51 |
-
print(f"all_articles_google length is {len(all_articles_google['articles'])}")
|
52 |
|
53 |
#Driver
|
54 |
def inference(newssource): #, date):
|
@@ -56,13 +41,10 @@ def inference(newssource): #, date):
|
|
56 |
if newssource == "Times Of India":
|
57 |
sentiment = sentiment_toi
|
58 |
all_articles = all_articles_toi
|
59 |
-
elif newssource == "
|
60 |
-
sentiment =
|
61 |
-
all_articles =
|
62 |
-
|
63 |
-
sentiment = sentiment_google
|
64 |
-
all_articles = all_articles_google
|
65 |
-
|
66 |
description = [entry['description'] for entry in all_articles['articles']]
|
67 |
content = [entry['content'] for entry in all_articles['articles']]
|
68 |
url = [entry['url'] for entry in all_articles['articles']]
|
@@ -91,7 +73,7 @@ def inference(newssource): #, date):
|
|
91 |
#Gradio Blocks
|
92 |
with gr.Blocks() as demo:
|
93 |
with gr.Row():
|
94 |
-
in_newssource = gr.Dropdown(["
|
95 |
#in_date = gr.Textbox(visible = False, value = today)
|
96 |
|
97 |
with gr.Row():
|
|
|
17 |
print("******** Outside Inference function ********")
|
18 |
print(f"HF_TOKEN is - {HF_TOKEN}")
|
19 |
|
20 |
+
#top-headlines
|
21 |
+
all_top_headlines = newsapi.get_top_headlines(country='in')
|
22 |
+
sentiment_tophead = ['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_top_headlines['articles']]
|
23 |
+
print(f"sentiment_tophead length is {len(sentiment_tophead)}")
|
24 |
+
print(f"all_top_headlines length is {len(all_top_headlines['articles'])}")
|
25 |
+
|
26 |
#times of india
|
27 |
all_articles_toi = newsapi.get_everything(sources='the-times-of-india',
|
28 |
domains= 'http://timesofindia.indiatimes.com', #'timesofindia.indiatimes.com',
|
|
|
34 |
print(f"sentiment_toi length is {len(sentiment_toi)}")
|
35 |
print(f"all_articles_toi length is {len(all_articles_toi['articles'])}")
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
#Driver
|
39 |
def inference(newssource): #, date):
|
|
|
41 |
if newssource == "Times Of India":
|
42 |
sentiment = sentiment_toi
|
43 |
all_articles = all_articles_toi
|
44 |
+
elif newssource == "Top Headlines":
|
45 |
+
sentiment = sentiment_tophead
|
46 |
+
all_articles = all_top_headlines
|
47 |
+
|
|
|
|
|
|
|
48 |
description = [entry['description'] for entry in all_articles['articles']]
|
49 |
content = [entry['content'] for entry in all_articles['articles']]
|
50 |
url = [entry['url'] for entry in all_articles['articles']]
|
|
|
73 |
#Gradio Blocks
|
74 |
with gr.Blocks() as demo:
|
75 |
with gr.Row():
|
76 |
+
in_newssource = gr.Dropdown(["Times Of India", "Top Headlines"], label='Choose a News Outlet')
|
77 |
#in_date = gr.Textbox(visible = False, value = today)
|
78 |
|
79 |
with gr.Row():
|