|
"""
|
|
Healthcheck script to verify the functionality of all components of the application.
|
|
Run this script to check if all dependencies are correctly installed and working.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import time
|
|
import traceback
|
|
|
|
def run_checks():
|
|
print("Starting health check for News Summarization and TTS Application...")
|
|
checks_passed = 0
|
|
checks_failed = 0
|
|
|
|
|
|
print("\n1. Checking imports...")
|
|
try:
|
|
|
|
import json
|
|
import re
|
|
|
|
|
|
import requests
|
|
import fastapi
|
|
import uvicorn
|
|
import streamlit
|
|
|
|
|
|
import pandas
|
|
import numpy
|
|
import bs4
|
|
|
|
|
|
import nltk
|
|
import networkx
|
|
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
|
|
|
|
|
import torch
|
|
import transformers
|
|
from transformers import pipeline
|
|
|
|
|
|
import deep_translator
|
|
from deep_translator import GoogleTranslator
|
|
import gtts
|
|
import pyttsx3
|
|
|
|
print("β
All imports successful.")
|
|
checks_passed += 1
|
|
except ImportError as e:
|
|
print(f"β Import error: {str(e)}")
|
|
print(f"Traceback: {traceback.format_exc()}")
|
|
checks_failed += 1
|
|
|
|
|
|
print("\n2. Checking NLTK data...")
|
|
try:
|
|
import nltk
|
|
nltk.data.find('tokenizers/punkt')
|
|
nltk.data.find('corpora/stopwords')
|
|
print("β
NLTK data verified.")
|
|
checks_passed += 1
|
|
except LookupError as e:
|
|
print(f"β NLTK data error: {str(e)}")
|
|
print("Trying to download necessary NLTK data...")
|
|
try:
|
|
nltk.download('punkt')
|
|
nltk.download('stopwords')
|
|
print("β
NLTK data downloaded successfully.")
|
|
checks_passed += 1
|
|
except Exception as e:
|
|
print(f"β Failed to download NLTK data: {str(e)}")
|
|
checks_failed += 1
|
|
|
|
|
|
print("\n3. Testing translation service...")
|
|
try:
|
|
from deep_translator import GoogleTranslator
|
|
translator = GoogleTranslator(source='en', target='hi')
|
|
text = "Hello, this is a test."
|
|
translated = translator.translate(text)
|
|
print(f"Original text: {text}")
|
|
print(f"Translated text: {translated}")
|
|
if translated and len(translated) > 0:
|
|
print("β
Translation service working.")
|
|
checks_passed += 1
|
|
else:
|
|
print("β Translation returned empty result.")
|
|
checks_failed += 1
|
|
except Exception as e:
|
|
print(f"β Translation error: {str(e)}")
|
|
print(f"Traceback: {traceback.format_exc()}")
|
|
checks_failed += 1
|
|
|
|
|
|
print("\n4. Testing Text-to-Speech service...")
|
|
try:
|
|
from gtts import gTTS
|
|
test_text = "ΰ€ͺΰ€°ΰ₯ΰ€ΰ₯ΰ€·ΰ€£ ΰ€ͺΰ€Ύΰ€ "
|
|
test_file = 'test_audio.mp3'
|
|
|
|
|
|
tts = gTTS(text=test_text, lang='hi', slow=False)
|
|
tts.save(test_file)
|
|
|
|
if os.path.exists(test_file) and os.path.getsize(test_file) > 0:
|
|
print("β
gTTS service working.")
|
|
|
|
try:
|
|
os.remove(test_file)
|
|
except:
|
|
pass
|
|
checks_passed += 1
|
|
else:
|
|
print("β gTTS failed to generate a valid audio file.")
|
|
checks_failed += 1
|
|
except Exception as e:
|
|
print(f"β Text-to-Speech error: {str(e)}")
|
|
print(f"Traceback: {traceback.format_exc()}")
|
|
checks_failed += 1
|
|
|
|
|
|
print("\n5. Testing sentiment analysis...")
|
|
try:
|
|
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
|
analyzer = SentimentIntensityAnalyzer()
|
|
test_text = "This product is excellent and I love it!"
|
|
scores = analyzer.polarity_scores(test_text)
|
|
print(f"Sentiment scores for '{test_text}': {scores}")
|
|
if 'compound' in scores:
|
|
print("β
Sentiment analysis working.")
|
|
checks_passed += 1
|
|
else:
|
|
print("β Sentiment analysis returned unexpected result.")
|
|
checks_failed += 1
|
|
except Exception as e:
|
|
print(f"β Sentiment analysis error: {str(e)}")
|
|
print(f"Traceback: {traceback.format_exc()}")
|
|
checks_failed += 1
|
|
|
|
|
|
print("\n6. Testing Transformer models...")
|
|
try:
|
|
from transformers import pipeline
|
|
sentiment_task = pipeline("sentiment-analysis", return_all_scores=False)
|
|
result = sentiment_task("I love using this application!")
|
|
print(f"Transformer sentiment analysis result: {result}")
|
|
print("β
Transformer models working.")
|
|
checks_passed += 1
|
|
except Exception as e:
|
|
print(f"β Transformer models error: {str(e)}")
|
|
print(f"Traceback: {traceback.format_exc()}")
|
|
checks_failed += 1
|
|
|
|
|
|
print("\n" + "="*50)
|
|
print(f"Health Check Summary: {checks_passed} checks passed, {checks_failed} checks failed")
|
|
|
|
if checks_failed == 0:
|
|
print("\nβ
All systems operational! The application should run correctly.")
|
|
return True
|
|
else:
|
|
print("\nβ Some checks failed. Please review the errors above.")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = run_checks()
|
|
if not success:
|
|
sys.exit(1) |