Shreyas94 commited on
Commit
92ccec4
1 Parent(s): 2517ac3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -136,17 +136,6 @@ def calculate_similarity(company_name, company_ticker, title, threshold=0.4):
136
 
137
  return weighted_similarity_score
138
 
139
- def calculate_title_similarity(news_list):
140
- similar_news = []
141
- for i, news1 in enumerate(news_list):
142
- for j, news2 in enumerate(news_list):
143
- if i != j:
144
- similarity_score = calculate_similarity(company_name, company_ticker, news1['title'])
145
- if similarity_score > 0.9:
146
- similar_news.append(news1)
147
- break # Exit inner loop to avoid duplicates
148
- return similar_news
149
-
150
  def analyze_sentiment(title):
151
  print("Analyzing sentiment...")
152
  # Perform sentiment analysis on the input title
@@ -157,14 +146,22 @@ def analyze_sentiment(title):
157
  print("Sentiment analyzed successfully.")
158
  return labels, scores
159
 
 
 
 
 
 
 
 
 
 
160
  def fetch_news(company_name, company_ticker, event_name, start_date, end_date, location, num_news, include_domains, exclude_domains):
161
  analyzed_news_name = fetch_and_analyze_news(company_name, company_ticker, event_name, start_date, end_date, location, num_news, include_domains, exclude_domains)
162
 
163
  above_threshold_news = [news for news in analyzed_news_name if news is not None and news['similarity_score'] >= 0.3]
164
  below_threshold_news = [news for news in analyzed_news_name if news is not None and news['similarity_score'] < 0.3]
165
 
166
- # Calculate similarity for above threshold news
167
- similar_news = calculate_title_similarity(above_threshold_news)
168
 
169
  above_threshold_df = pd.DataFrame(above_threshold_news)
170
  below_threshold_df = pd.DataFrame(below_threshold_news)
 
136
 
137
  return weighted_similarity_score
138
 
 
 
 
 
 
 
 
 
 
 
 
139
  def analyze_sentiment(title):
140
  print("Analyzing sentiment...")
141
  # Perform sentiment analysis on the input title
 
146
  print("Sentiment analyzed successfully.")
147
  return labels, scores
148
 
149
+ def calculate_title_similarity(news_list, company_name, company_ticker):
150
+ """Calculate similarity score between news titles."""
151
+ similar_news = []
152
+ for news in news_list:
153
+ similarity_score = calculate_similarity(company_name, company_ticker, news['title'])
154
+ if similarity_score > 0.9:
155
+ similar_news.append(news)
156
+ return similar_news
157
+
158
  def fetch_news(company_name, company_ticker, event_name, start_date, end_date, location, num_news, include_domains, exclude_domains):
159
  analyzed_news_name = fetch_and_analyze_news(company_name, company_ticker, event_name, start_date, end_date, location, num_news, include_domains, exclude_domains)
160
 
161
  above_threshold_news = [news for news in analyzed_news_name if news is not None and news['similarity_score'] >= 0.3]
162
  below_threshold_news = [news for news in analyzed_news_name if news is not None and news['similarity_score'] < 0.3]
163
 
164
+ similar_news = calculate_title_similarity(above_threshold_news, company_name, company_ticker)
 
165
 
166
  above_threshold_df = pd.DataFrame(above_threshold_news)
167
  below_threshold_df = pd.DataFrame(below_threshold_news)