Jayeshbhaal commited on
Commit
ae55747
1 Parent(s): cf54de7
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -22,6 +22,9 @@ 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',
@@ -59,16 +62,12 @@ def inference(newssource): #, date):
59
  print(f"sentiment length is - {len(sentiment)}")
60
 
61
  dictnews = { 'description' : description, 'content' : content, 'url' : url, 'urlToImage' : urlToImage, 'sentiment' : sentiment,}
62
- #dictnews = { 'description' : [entry['description'] for entry in all_articles['articles']],
63
- # 'content' : [entry['content'] for entry in all_articles['articles']],
64
- # 'url' : [entry['url'] for entry in all_articles['articles']],
65
- # 'urlToImage' : [entry['urlToImage'] for entry in all_articles['articles']],
66
- # 'sentiment' : sentiment,
67
- # }
68
  df = pd.DataFrame.from_dict(dictnews)
69
  print(f"dataframe shape is :,{df.shape}")
70
- html_out = "<img src= " + dictnews['urlToImage'][0] + ">"
71
- print(f"html_out is : {html_out}")
 
72
  return df, html_out
73
 
74
 
 
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
+ print("************** sentiment start ****************")
26
+ print(sentiment_tophead)
27
+ print("************** sentiment end ****************")
28
 
29
  #times of india
30
  all_articles_toi = newsapi.get_everything(sources='the-times-of-india',
 
62
  print(f"sentiment length is - {len(sentiment)}")
63
 
64
  dictnews = { 'description' : description, 'content' : content, 'url' : url, 'urlToImage' : urlToImage, 'sentiment' : sentiment,}
65
+
 
 
 
 
 
66
  df = pd.DataFrame.from_dict(dictnews)
67
  print(f"dataframe shape is :,{df.shape}")
68
+ if dictnews['urlToImage'][0] is not None :
69
+ html_out = "<img src= " + dictnews['urlToImage'][0] + ">"
70
+ print(f"html_out is : {html_out}")
71
  return df, html_out
72
 
73