A Python-based email analysis and response generation system that uses NLP models to analyze emails, detect sentiment, generate summaries, and create appropriate responses.
- π§ Email Analysis
- π Sentiment Detection
- π Smart Summarization
- π¬ Response Generation
- π¨ Modern Web Interface
- β‘ Real-time Processing
The project consists of two main components:
-
Core Engine (
email_agent.py):- Email analysis and processing
- Sentiment detection using DistilBERT
- Summarization using BART
- Response generation using GPT-2
-
Web Interface (
app.py):- Streamlit-based UI
- Real-time processing
- Beautiful and responsive design
- Clone the repository:
git clone https://github.com/rishabharaj/Email-AI-agent.git
cd Email-AI-agent- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Run the Streamlit app:
streamlit run app.py-
Open your browser and navigate to the provided URL (usually http://localhost:8501)
-
Paste your email text and click "Analyze Email"
Email-AI-agent/
βββ app.py # Streamlit web interface
βββ email_agent.py # Core email processing logic
βββ requirements.txt # Project dependencies
βββ README.md # Project documentation
βββ .gitignore # Git ignore file
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Hugging Face for the transformer models
- Streamlit for the web framework
- NLTK for natural language processing tools
- Email Analysis: Automatically analyzes email content
- Sentiment Detection: Identifies the emotional tone of the email
- Smart Summarization: Generates concise summaries of email content
- Response Generation: Creates appropriate responses when needed
- Modern Web Interface: Beautiful and user-friendly UI using Streamlit
- Real-time Processing: Instant analysis and results
-
EmailAgent Class (
email_agent.py)- Uses three main NLP pipelines:
- Sentiment Analysis: Using DistilBERT model
- Summarization: Using BART model
- Text Generation: Using GPT-2 model
- Key Functions:
analyze_email(): Performs simultaneous summarization and sentiment analysisneeds_response(): Determines if a response is needed based on sentimentgenerate_response(): Creates a response using the email summaryprocess_email(): Orchestrates the entire process
- Uses three main NLP pipelines:
-
Web Interface (
app.py)- Built with Streamlit
- Features:
- Clean, modern UI design
- Real-time progress tracking
- Color-coded sentiment analysis
- Responsive layout
- Error handling and user feedback
-
DistilBERT (for sentiment analysis)
- Model:
distilbert-base-uncased-finetuned-sst-2-english - Purpose: Analyzes email sentiment (positive/negative)
- Output: Sentiment label and confidence score
- Model:
-
BART (for summarization)
- Model:
facebook/bart-large-cnn - Purpose: Generates concise email summaries
- Parameters:
- max_length: 80 characters
- min_length: 20 characters
- num_beams: 4
- length_penalty: 0.8
- Model:
-
GPT-2 (for response generation)
- Model:
gpt2 - Purpose: Generates appropriate email responses
- Parameters:
- max_length: 100 characters
- temperature: 0.7
- top_p: 0.9
- repetition_penalty: 1.2
- Model:
torch: PyTorch for deep learning operationstransformers: Hugging Face Transformers library for NLP modelsnltk: Natural Language Toolkit for text processingstreamlit: Web application frameworkpython-dotenv: Environment variable management
- Create a virtual environment:
python -m venv venv- Activate the virtual environment:
- Windows:
.\venv\Scripts\activate- Linux/Mac:
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Run the application:
streamlit run app.pyThe application will open in your default web browser at http://localhost:8501
-
Input Email
- Paste your email text into the input area
- Click "Analyze Email" button
-
Analysis Process
- The system will:
- Generate a concise summary
- Analyze sentiment
- Determine if a response is needed
- Generate a response (if required)
- The system will:
-
Results Display
- Summary of the email
- Sentiment analysis with color coding
- Response decision
- Generated response (if applicable)
You can customize the following aspects:
-
Summary Length
- Adjust
max_lengthandmin_lengthinanalyze_email() - Modify
length_penaltyfor different summary styles
- Adjust
-
Response Generation
- Change prompt in
generate_response() - Adjust generation parameters (temperature, top_p, etc.)
- Change prompt in
-
UI Styling
- Modify CSS in
app.py - Adjust layout and colors
- Modify CSS in
-
Email Analysis
- Text is processed through BART model for summarization
- DistilBERT analyzes sentiment simultaneously
- Results are combined for comprehensive analysis
-
Response Decision
- Based on sentiment and confidence score
- Triggers response generation when:
- Sentiment is negative, or
- Positive sentiment with high confidence (>0.9)
-
Response Generation
- Uses email summary as context
- Generates professional, concise responses
- Ensures complete sentences and proper formatting
- First run might take time as it downloads ML models
- Requires stable internet connection for model downloads
- Processing time depends on email length and complexity
Feel free to contribute to this project by:
- Forking the repository
- Creating a feature branch
- Submitting a pull request
This project is open-source and available under the MIT License.