Jayeshbhaal commited on
Commit
283921a
1 Parent(s): bec46f5
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -5,4 +5,25 @@ import pandas as pd
5
  from newsapi import NewsApiClient
6
  from datetime import date, timedelta
7
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
 
5
  from newsapi import NewsApiClient
6
  from datetime import date, timedelta
7
  from transformers import pipeline
8
+
9
+ # Model 2: Sentence Transformer
10
+ #API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/msmarco-distilbert-base-tas-b"
11
+ HF_TOKEN = os.environ["newsapi"]
12
+ #headers = {"Authorization": f"Bearer {HF_TOKEN}"}
13
+
14
+ classifier = pipeline(model="cardiffnlp/twitter-roberta-base-sentiment")
15
+ sentiment = ['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']]
16
+ # Initialization
17
+ newsapi = NewsApiClient(api_key=HF_TOKEN)
18
+
19
+ # /v2/everything
20
+ all_articles = newsapi.get_everything(#q='bitcoin',
21
+ sources='the-times-of-india',
22
+ domains='timesofindia.indiatimes.com',
23
+ from_param='2022-10-30',
24
+ to='2022-10-30',
25
+ language='en',
26
+ sort_by='relevancy',)
27
+ #page=2)
28
+ all_articles['articles']
29