v1shal's picture
first_commit
b396e94
# import json
# import time
# from news_extraction import extract_news
# from news_summarisation import summarize_text
# from news_sentiment import analyze_sentiment
# from topic_extraction import preprocess_text, train_lda, extract_topic_words
# from comparative_analysis import comparative_sentiment_analysis
# from text_to_speech import text_to_speech # βœ… Import the TTS function
# def main():
# # User input for the company/topic
# company = input("Enter the company name for analysis: ").strip()
# # Extract news articles
# start_time = time.time()
# articles = extract_news(company)
# extraction_time = time.time() - start_time
# if not articles:
# print("No news articles found. Try a different company.")
# return
# articles_data = [] # List to store processed articles
# # Extract texts from articles for sentiment analysis
# texts = [article["text"] for article in articles]
# # Perform sentiment analysis
# start_time = time.time()
# sentiment_results = analyze_sentiment(texts)
# sentiment_time = time.time() - start_time
# # Process each article
# for i, (article, sentiment) in enumerate(zip(articles, sentiment_results["Predicted Sentiment"]), start=1):
# start_time = time.time()
# summary = summarize_text(article["text"]) # Summarize article
# summarization_time = time.time() - start_time
# # Extract topics for the specific article
# preprocessed_text = preprocess_text([article["text"]])
# lda_model, dictionary = train_lda(preprocessed_text)
# topic_words = extract_topic_words(lda_model)
# article_entry = {
# "Title": article["title"],
# "Summary": summary,
# "Sentiment": sentiment,
# "Topics": topic_words
# }
# articles_data.append(article_entry)
# # Perform comparative sentiment analysis
# analysis_result = comparative_sentiment_analysis(company, articles_data)
# # βœ… Generate a summary speech for the entire report
# final_summary = f"{company}’s latest news coverage is mostly {analysis_result['Final Sentiment Analysis']}."
# audio_file = text_to_speech(final_summary) # Generate Hindi TTS
# # βœ… Construct final JSON output
# output = {
# "Company": company,
# "Articles": articles_data,
# "Comparative Sentiment Score": analysis_result,
# "Final Sentiment Analysis": final_summary,
# "Audio": f"[Play {audio_file}]" # βœ… Include a playable reference
# }
# # Print JSON output
# print(json.dumps(output, indent=4, ensure_ascii=False))
# # Save JSON output to file
# with open(f"{company}_news_analysis.json", "w", encoding="utf-8") as json_file:
# json.dump(output, json_file, indent=4, ensure_ascii=False)
# if __name__ == "__main__":
# main()
import json
import time
from utils.news_extraction import extract_news
from utils.news_summarisation import summarize_text
from utils.news_sentiment import analyze_sentiment
from utils.topic_extraction import preprocess_text, train_lda, extract_topic_words
from utils.comparative_analysis import comparative_sentiment_analysis
from utils.text_to_speech import text_to_speech # βœ… Import the TTS function
def analyze_company_news(company):
# Extract news articles
start_time = time.time()
articles = extract_news(company)
extraction_time = time.time() - start_time
if not articles:
return {"message": "No news articles found. Try a different company."}
articles_data = [] # List to store processed articles
# Extract texts from articles for sentiment analysis
texts = [article["text"] for article in articles]
# Perform sentiment analysis
start_time = time.time()
sentiment_results = analyze_sentiment(texts)
sentiment_time = time.time() - start_time
# Process each article
for i, (article, sentiment) in enumerate(zip(articles, sentiment_results["Predicted Sentiment"]), start=1):
start_time = time.time()
summary = summarize_text(article["text"]) # Summarize article
summarization_time = time.time() - start_time
# Extract topics for the specific article
preprocessed_text = preprocess_text([article["text"]])
lda_model, dictionary = train_lda(preprocessed_text)
topic_words = extract_topic_words(lda_model)
article_entry = {
"Title": article["title"],
"Summary": summary,
"Sentiment": sentiment,
"Topics": topic_words
}
articles_data.append(article_entry)
# Perform comparative sentiment analysis
analysis_result = comparative_sentiment_analysis(company, articles_data)
# βœ… Generate a summary speech for the entire report
final_summary = f"{company}’s latest news coverage is mostly {analysis_result['Final Sentiment Analysis']}."
audio_file = text_to_speech(final_summary) # Generate TTS
# βœ… Construct final JSON output
output = {
"Company": company,
"Articles": articles_data,
"Comparative Sentiment Score": analysis_result,
"Audio": f"[Play {audio_file}]" # βœ… Include a playable reference
}
return output
# if __name__ == "__main__":
# company = input("Enter the company name for analysis: ").strip()
# result = analyze_company_news(company)
# print(json.dumps(result, indent=4, ensure_ascii=False))