Meggison/ELIZA

โ˜… 0Forks 0PythonGitHub โ†—Compare

README

Modern ELIZA Chatbot ๐Ÿค–

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.

Python Version License: MIT

ELIZA Demo

โœจ Features

  • ๐ŸŽฏ 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

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip (Python package installer)
  • Virtual environment (recommended)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/ELIZA.git
cd ELIZA
  1. 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
  1. Install dependencies:
pip install -e .

Running ELIZA

Web Interface

# Start the Flask server
python -m eliza.web.app

# Open your browser and navigate to:
# http://localhost:5000

Command Line Interface

python -m eliza.cli

# Or with session file specification:
python -m eliza.cli --session-file my_session.json

๐Ÿ“ Project Structure

ELIZA/
โ”œโ”€โ”€ 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

๐Ÿ’ก Usage Examples

Web Interface

  1. Start a conversation:
from eliza.web.app import main
main()
  1. Open your browser to http://localhost:5000
  2. Start chatting!

Command Line

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?"

Custom Response Patterns

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)

๐Ÿ”ง Configuration

Environment Variables

Create a .env file in the project root:

FLASK_ENV=development
DEBUG=True
SESSION_FILE=eliza_session.json

Response Patterns

Patterns are defined in eliza/core/patterns.py. Each pattern includes:

  • Regular expression for matching user input
  • List of possible responses
  • Placeholders for captured groups

๐Ÿ“Š Analysis Tools

Emotion Tracking

from eliza.utils.text import detect_emotion

emotion = detect_emotion("I'm feeling really anxious about this")
print(emotion)  # Output: "anxious"

Session Analysis

# 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]

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Original ELIZA by Joseph Weizenbaum
  • Modern UI inspired by ChatGPT
  • Contributors and maintainers

Contributors

Meggison

Issues