scary29/Summarizer
News Summarization & TTS Application
A Python-based application that fetches news articles for a given company, performs sentiment analysis, generates a comparative report, and provides a text-to-speech (TTS) output in Hindi. The application features a Gradio web interface and a FastAPI endpoint for easy interaction.
Features
- News Extraction: Fetches the latest news articles about a company using the NewsAPI.
- Sentiment Analysis: Analyzes the sentiment of article summaries using a pre-trained transformer model.
- Comparative Analysis: Compares sentiment and topics across articles.
- Text-to-Speech (TTS): Generates an audio summary in Hindi using gTTS.
- Web Interface: Interactive UI built with Gradio.
- API: FastAPI endpoint for programmatic access.
Prerequisites
- Python 3.8 or higher
- A NewsAPI key (sign up at NewsAPI.org to get one)
Installation
1. Clone the Repository
# Clone the repository
git clone https://github.com/pavan091220002/summarizer.git
# Navigate into the directory
cd news-summarizer2. Install Dependencies
pip install -r requirements.txt3. Configure NewsAPI Key
Replace the api_key in utils.py with your own NewsAPI key:
But i already mentioned my api
newsapi = NewsApiClient(api_key="YOUR_API_KEY_HERE")Save and exit.
Usage
Running the Gradio Interface
Launch the web interface to analyze companies interactively:
python app.py- Open your browser and go to http://0.0.0.0:7860.
- Enter a company name (e.g., "Tesla") and click "Analyze" to see the sentiment report and hear the Hindi TTS output.
Using the FastAPI Endpoint
Start the API server:
uvicorn api:app --reload- Access the endpoint at http://localhost:8000/analyze/{company} (e.g., http://localhost:8000/analyze/Tesla).
- The API returns a JSON response with the analysis results.
Example Output
For input "Tesla":
- Sentiment Report: A JSON-formatted report with article details, sentiment distribution, and comparative analysis.
- Audio: An MP3 file with a Hindi summary (e.g., "Tesla की नवीनतम समाचार कवरेज ज्यादातर सकारात्मक है।").
Project Structure
news-summarizer/
├── api.py # FastAPI endpoint
├── app.py # Gradio interface
├── utils.py # Core logic (news extraction, sentiment analysis, TTS)
├── requirements.txt # Dependencies
└── README.md # This fileDeployment by using Hugging space
- Create a new space
- upload your files
- Build the application
Check out my Link: https://scary29-summarizer.hf.space/
https://scary29-summarizer.hf.space/Dependencies
requests: For HTTP requests.beautifulsoup4: For web scraping (not used in current code but included).transformers&torch: For sentiment analysis and summarization.gtts: For text-to-speech generation.gradio: For the web interface.fastapi&uvicorn: For the API server.newsapi-python: For fetching news articles.numpy: For numerical operations.
See requirements.txt for version details.
Notes
- The application uses
distilbert-base-uncased-finetuned-sst-2-englishfor sentiment analysis andfacebook/bart-large-cnnfor summarization. - The TTS output is in Hindi, but the sentiment report is in English.
- If no articles are found, an error message is returned.
Limitations
- Requires an active internet connection for NewsAPI and model downloads.
- The NewsAPI free tier has rate limits (e.g., 100 requests/day).
- Sentiment analysis accuracy depends on the pre-trained model and article summaries.
Contributing
Feel free to fork this repository, submit issues, or create pull requests to improve the project!
