Skip to content

Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot

Notifications You must be signed in to change notification settings

daley-mottley/Basketball-Analysis-Chatbot

Β 
Β 

Repository files navigation

πŸ€ Basketball Analysis Chatbot

A sophisticated basketball analysis chatbot built with LangChain, Hugging Face Llama models, and Pinecone vector database. This application provides intelligent responses to basketball-related questions using advanced AI and vector search capabilities.


Basketball.statistical.analysis.chatbot.mp4

✨ Features

  • πŸ€– AI-Powered Responses: Uses Hugging Face language models for natural conversation
  • πŸ” Vector Search: Pinecone integration for semantic search of basketball knowledge
  • πŸ“š Comprehensive Knowledge Base: Built-in basketball rules, positions, strategies, and statistics
  • 🌐 Modern Web Interface: Beautiful Streamlit-based UI with real-time chat
  • ⚑ Quick Actions: Pre-built buttons for common basketball questions
  • πŸ”„ Real-time Updates: Dynamic knowledge base refresh capabilities

πŸ› οΈ Technology Stack

  • LangChain: Conversation management and AI orchestration
  • Hugging Face: Language models and transformers
  • Pinecone: Vector database for semantic search
  • Streamlit: Web application framework
  • Sentence Transformers: Text embeddings
  • Python: Core programming language

πŸ“‹ Prerequisites

  • Python 3.8 or higher
  • Hugging Face account and API token
  • Pinecone account and API key (optional but recommended)
  • Git (for cloning the repository)

πŸš€ Quick Start

1. Clone the Repository

git clone <repository-url>
cd basketball-chatbot

2. Run the Setup Script

python setup.py

The setup script will:

  • Check Python version compatibility
  • Install all required dependencies
  • Guide you through API key configuration
  • Test the installation
  • Create sample basketball knowledge

3. Manual Setup (Alternative)

If you prefer manual setup:

Install Dependencies

pip install -r requirements.txt

Configure Environment Variables

Create a .env file in the project root:

# Hugging Face API Token
HUGGINGFACE_API_TOKEN=your_huggingface_token_here

# Pinecone API Key (optional)
PINECONE_API_KEY=your_pinecone_api_key_here
PINECONE_ENVIRONMENT=your_pinecone_environment_here
PINECONE_INDEX_NAME=basketball-analysis

# Model Configuration
MODEL_NAME=microsoft/DialoGPT-medium
EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2

4. Run the Application

streamlit run app.py

The application will open in your default browser at http://localhost:8501.

πŸ”‘ API Keys Setup

Hugging Face API Token

  1. Go to Hugging Face Settings
  2. Create a new token
  3. Copy the token and add it to your .env file

Pinecone API Key (Optional)

  1. Go to Pinecone Console
  2. Create an account and get your API key
  3. Note your environment (e.g., us-east-1-aws)
  4. Add both to your .env file

Note: The chatbot will work without Pinecone, but vector search capabilities will be limited.

πŸ€ Basketball Knowledge Base

The chatbot includes comprehensive basketball knowledge covering:

πŸ“‹ Rules and Regulations

  • Basic basketball rules
  • Scoring system
  • Game duration and timing
  • Fouls and violations

πŸ‘₯ Player Positions

  • Point Guard (PG)
  • Shooting Guard (SG)
  • Small Forward (SF)
  • Power Forward (PF)
  • Center (C)

🎯 Strategies and Tactics

  • Pick and roll
  • Zone defense
  • Man-to-man defense
  • Fast break
  • Half-court offense

πŸ“Š Statistics and Analytics

  • Points per game (PPG)
  • Rebounds per game (RPG)
  • Assists per game (APG)
  • Field goal percentage (FG%)
  • Three-point percentage (3P%)
  • Player efficiency rating (PER)

πŸ’¬ Usage Examples

Basic Questions

  • "What are the rules of basketball?"
  • "How many points is a three-pointer worth?"
  • "What is a pick and roll?"

Player Analysis

  • "What are the responsibilities of a point guard?"
  • "How do you calculate field goal percentage?"
  • "What makes a good shooting guard?"

Strategy Questions

  • "What is zone defense?"
  • "How does a fast break work?"
  • "What are the different offensive strategies?"

πŸ—οΈ Project Structure

basketball-chatbot/
β”œβ”€β”€ app.py                 # Main Streamlit application
β”œβ”€β”€ basketball_chatbot.py  # Core chatbot logic
β”œβ”€β”€ basketball_knowledge.py # Basketball knowledge base
β”œβ”€β”€ vector_store.py        # Pinecone vector database operations
β”œβ”€β”€ config.py             # Configuration management
β”œβ”€β”€ setup.py              # Setup script
β”œβ”€β”€ requirements.txt      # Python dependencies
β”œβ”€β”€ env_example.txt       # Environment variables template
β”œβ”€β”€ README.md            # This file
└── .env                 # Environment variables (created during setup)

πŸ”§ Configuration Options

Model Configuration

You can customize the language model in config.py:

MODEL_NAME = "meta-llama/Llama-2-7b-chat-hf"  # For Llama-2 (requires access)
MODEL_NAME = "microsoft/DialoGPT-medium"      # Default (no access required)

Vector Database Settings

VECTOR_DIMENSION = 384    # Embedding dimension
METRIC = "cosine"        # Similarity metric
CHUNK_SIZE = 1000        # Text chunk size
CHUNK_OVERLAP = 200      # Chunk overlap

πŸš€ Advanced Features

Custom Knowledge Addition

You can extend the basketball knowledge base by modifying basketball_knowledge.py:

def get_custom_knowledge(self):
    return [
        {
            "title": "Your Custom Topic",
            "content": "Your custom basketball knowledge here."
        }
    ]

Model Customization

To use different models, update the configuration:

# For Llama-2 (requires Hugging Face access)
MODEL_NAME = "meta-llama/Llama-2-7b-chat-hf"

# For other models
MODEL_NAME = "gpt2"  # Smaller model
MODEL_NAME = "EleutherAI/gpt-neo-125M"  # Alternative

πŸ› Troubleshooting

Common Issues

  1. Import Errors: Make sure all dependencies are installed

    pip install -r requirements.txt
  2. API Key Errors: Verify your API keys are correctly set in .env

    cat .env  # Check your environment variables
  3. Model Loading Issues: Try using the default DialoGPT model

    MODEL_NAME = "microsoft/DialoGPT-medium"
  4. Pinecone Connection Issues: Check your environment and API key

    PINECONE_ENVIRONMENT = "us-east-1-aws"  # Verify your environment

Performance Optimization

  • Use smaller models for faster responses
  • Reduce MAX_LENGTH for quicker generation
  • Adjust TEMPERATURE for more focused responses

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

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

πŸ™ Acknowledgments

  • LangChain for conversation management
  • Hugging Face for language models
  • Pinecone for vector database
  • Streamlit for the web interface
  • Basketball community for knowledge and insights

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the troubleshooting section
  2. Review the configuration options
  3. Open an issue on GitHub
  4. Check the documentation

Happy Basketball Analysis! πŸ€

About

Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot Basketball Analysis Chatbot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%