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
- π€ 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
- 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
- Python 3.8 or higher
- Hugging Face account and API token
- Pinecone account and API key (optional but recommended)
- Git (for cloning the repository)
git clone <repository-url>
cd basketball-chatbotpython setup.pyThe setup script will:
- Check Python version compatibility
- Install all required dependencies
- Guide you through API key configuration
- Test the installation
- Create sample basketball knowledge
If you prefer manual setup:
pip install -r requirements.txtCreate 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-v2streamlit run app.pyThe application will open in your default browser at http://localhost:8501.
- Go to Hugging Face Settings
- Create a new token
- Copy the token and add it to your
.envfile
- Go to Pinecone Console
- Create an account and get your API key
- Note your environment (e.g.,
us-east-1-aws) - Add both to your
.envfile
Note: The chatbot will work without Pinecone, but vector search capabilities will be limited.
The chatbot includes comprehensive basketball knowledge covering:
- Basic basketball rules
- Scoring system
- Game duration and timing
- Fouls and violations
- Point Guard (PG)
- Shooting Guard (SG)
- Small Forward (SF)
- Power Forward (PF)
- Center (C)
- Pick and roll
- Zone defense
- Man-to-man defense
- Fast break
- Half-court offense
- Points per game (PPG)
- Rebounds per game (RPG)
- Assists per game (APG)
- Field goal percentage (FG%)
- Three-point percentage (3P%)
- Player efficiency rating (PER)
- "What are the rules of basketball?"
- "How many points is a three-pointer worth?"
- "What is a pick and roll?"
- "What are the responsibilities of a point guard?"
- "How do you calculate field goal percentage?"
- "What makes a good shooting guard?"
- "What is zone defense?"
- "How does a fast break work?"
- "What are the different offensive strategies?"
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)
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_DIMENSION = 384 # Embedding dimension
METRIC = "cosine" # Similarity metric
CHUNK_SIZE = 1000 # Text chunk size
CHUNK_OVERLAP = 200 # Chunk overlapYou 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."
}
]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-
Import Errors: Make sure all dependencies are installed
pip install -r requirements.txt
-
API Key Errors: Verify your API keys are correctly set in
.envcat .env # Check your environment variables -
Model Loading Issues: Try using the default DialoGPT model
MODEL_NAME = "microsoft/DialoGPT-medium"
-
Pinecone Connection Issues: Check your environment and API key
PINECONE_ENVIRONMENT = "us-east-1-aws" # Verify your environment
- Use smaller models for faster responses
- Reduce
MAX_LENGTHfor quicker generation - Adjust
TEMPERATUREfor more focused responses
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- LangChain for conversation management
- Hugging Face for language models
- Pinecone for vector database
- Streamlit for the web interface
- Basketball community for knowledge and insights
If you encounter any issues or have questions:
- Check the troubleshooting section
- Review the configuration options
- Open an issue on GitHub
- Check the documentation
Happy Basketball Analysis! π