A modern, context-aware implementation of the classic ELIZA chatbot, featuring both a sleek web interface and command-line interaction. This version combines the original pattern-matching approach with enhanced natural language processing and emotional intelligence.
-
๐ฏ Context-Aware Conversations
- Maintains conversation history
- Provides contextually relevant responses
-
๐ Modern Web Interface
- ChatGPT-style UI
- Real-time responses
- Mobile-responsive design
- Typing indicators
- Session persistence
-
๐ง Advanced NLP Capabilities
- Pattern matching with regular expressions
- Subject-object extraction
- N-gram analysis
-
๐ Analysis Tools
- Conversation history tracking
- Response pattern usage statistics
- Perplexity calculation
- Python 3.8 or higher
- pip (Python package installer)
- Virtual environment (recommended)
- Clone the repository:
git clone https://github.com/yourusername/ELIZA.git
cd ELIZA- Create and activate a virtual environment:
# On macOS/Linux:
python -m venv venv
source venv/bin/activate
# On Windows:
python -m venv venv
venv\Scripts\activate- Install dependencies:
pip install -e .# Start the Flask server
python -m eliza.web.app
# Open your browser and navigate to:
# http://localhost:5000python -m eliza.cli
# Or with session file specification:
python -m eliza.cli --session-file my_session.jsonELIZA/
โโโ eliza/ # Main package directory
โ โโโ core/ # Core chatbot functionality
โ โ โโโ chatbot.py # Main ELIZA implementation
โ โ โโโ patterns.py # Response patterns
โ โโโ utils/ # Utility functions
โ โ โโโ text.py # Text processing utilities
โ โโโ web/ # Web interface
โ โโโ static/ # Static assets
โ โโโ templates/ # HTML templates
โโโ tests/ # Test suite
โโโ docs/ # Documentation
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ setup.py # Package configuration
- Start a conversation:
from eliza.web.app import main
main()- Open your browser to
http://localhost:5000 - Start chatting!
from eliza.core.chatbot import Eliza
# Initialize ELIZA
eliza = Eliza()
# Get a response
response = eliza.respond("I've been feeling sad lately")
print(response)
# Output: "I hear that you're feeling down. Would you like to tell me more about what's been making you feel this way?"from eliza.core.patterns import ResponsePattern
import re
# Create a custom pattern
custom_pattern = ResponsePattern(
pattern=re.compile(r'I love (.*)', re.IGNORECASE),
responses=[
"Tell me more about your feelings towards {}",
"What makes you love {} so much?",
"Since when have you felt this way about {}?"
]
)
# Add to ELIZA's patterns
eliza = Eliza()
eliza.responses.append(custom_pattern)Create a .env file in the project root:
FLASK_ENV=development
DEBUG=True
SESSION_FILE=eliza_session.jsonPatterns are defined in eliza/core/patterns.py. Each pattern includes:
- Regular expression for matching user input
- List of possible responses
- Placeholders for captured groups
from eliza.utils.text import detect_emotion
emotion = detect_emotion("I'm feeling really anxious about this")
print(emotion) # Output: "anxious"# Load a session file
with open('eliza_session.json', 'r') as f:
session = json.load(f)
# Analyze emotions over time
emotions = [msg['emotion'] for msg in session if 'emotion' in msg]This project is licensed under the MIT License - see the LICENSE file for details.
- Original ELIZA by Joseph Weizenbaum
- Modern UI inspired by ChatGPT
- Contributors and maintainers
