An advanced emotion detection and chatbot system that combines machine learning models with conversational AI to analyze emotions in text and provide intelligent responses.
CustomGPT is a comprehensive AI system that integrates emotion detection with chatbot capabilities. The project features:
- Emotion Detection Pipeline: Uses LightGBM models trained on emotion datasets to detect and classify emotions in text
- Local Chatbot: Powered by Microsoft's Phi-4 model for offline text generation
- OpenAI Integration: Customer service chatbot with emotion-aware responses
- Multi-Model Support: Includes RoBERTa and other transformer models for emotion analysis
- Data Processing: Complete pipeline for emotion dataset preparation and model training
The system is particularly useful for customer service applications, sentiment analysis, and building emotion-aware conversational AI.
You will need Python 3.8+ installed on your machine to run this project.
- Python 3.8 or higher
- Git
- Optional: CUDA-capable GPU for faster model inference
- Clone the repository:
git clone https://github.com/Luxchar/CustomGPT.git
cd CustomGPT- Install the dependencies:
pip install -r requirements.txt- For OpenAI integration: Create a
.envfile in the root directory and add your OpenAI API key:
OPENAI_API_KEY=your_api_key_here- For emotion detection: The pre-trained LightGBM models are included in the
notebooks/lightgbm_ultimate_saved/directory.
Run the local Phi-4 powered chatbot that works entirely offline:
streamlit run src/main.pyRun the emotion-aware customer service chatbot:
streamlit run src/main_openai.pyUse the emotion detection system programmatically:
from src.emotion_pipeline import EmotionDetectionPipeline
# Initialize the pipeline
pipeline = EmotionDetectionPipeline()
model_path = "./notebooks/lightgbm_ultimate_saved/lightgbm_ultimate_rescued_20250706_060702"
pipeline.load_model(model_path)
# Analyze a single text
result = pipeline.predict_single("I absolutely love this product!")
print(f"Major emotion: {result['major_emotion']} ({result['major_confidence']:.3f})")
# Batch processing
texts = ["Great product!", "Terrible service!", "It's okay, I guess."]
df_results = pipeline.predict_batch(texts, save_csv="predictions.csv")Explore the Jupyter notebooks for data processing and model training:
jupyter notebook notebooks/Key notebooks:
data_prep_yann.ipynb: Data preparation and preprocessingdetecteur_emotion_*.ipynb: Emotion detection model trainingtext-generation*.ipynb: Text generation experiments
- 30+ Emotion Categories: Detects emotions like joy, anger, sadness, fear, surprise, etc.
- Multi-Model Architecture: LightGBM ensemble with TF-IDF and SVD features
- Batch Processing: Efficient processing of large text datasets
- Confidence Scores: Returns probability scores for all emotions
- Local Inference: Phi-4 model runs entirely on your machine
- Streaming Responses: Real-time text generation with streaming UI
- Emotion-Aware Responses: Customer service bot adapts responses based on detected emotions
- Memory: Maintains conversation context across interactions
- Multiple Datasets: Support for GoEmotions and custom emotion datasets
- Feature Engineering: Advanced text preprocessing and feature extraction
- Model Training: Complete pipeline for training custom emotion detection models
- Primary Model: LightGBM Ultimate with TF-IDF and SVD features
- Alternative Models: RoBERTa-based emotion classifiers
- Training Data: GoEmotions dataset and custom review datasets
- Features: Word/character n-grams, semantic embeddings, statistical features
- Local Model: Microsoft Phi-4-mini-instruct (CPU optimized)
- Cloud Model: OpenAI GPT-3.5-turbo integration
- Optimization: Quantization and optimization for fast inference
Create a .env file with the following variables:
OPENAI_API_KEY=your_openai_api_key
MODEL_PATH=./notebooks/lightgbm_ultimate_saved/lightgbm_ultimate_rescued_20250706_060702Update model paths in the configuration files:
- Emotion models:
notebooks/lightgbm_ultimate_saved/ - Language models: Downloaded automatically via Hugging Face
For production deployment, configure Streamlit in .streamlit/config.toml:
[server]
port = 8501
address = "0.0.0.0"
[theme]
primaryColor = "#FF6B6B"
backgroundColor = "#FFFFFF"
secondaryBackgroundColor = "#F0F2F6"If you want to contribute to this project, you can fork this repository and make a pull request with your changes.
- Follow PEP 8 style guidelines
- Add docstrings to all functions and classes
- Include unit tests for new features
- Update documentation for any API changes
- Additional emotion categories
- Performance optimizations
- New model architectures
- UI/UX improvements
- Documentation and tutorials
Anyone is welcome to contribute to this project.
This project is under the MIT license.
# Quick emotion detection
from src.emotion_pipeline import quick_predict
result = quick_predict("This product is absolutely amazing!")
print(f"Emotion: {result['major_emotion']} (confidence: {result['major_confidence']:.2f})")For more examples and detailed documentation, check the notebooks/ directory.