Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ All notable changes to this project will be documented in this file.
- Updated `scripts/install.sh` to install requirements without the `--user` flag.
- Documented virtual environment setup in the Quick Start guide.
- Changed prerequisite to recommend Python 3.10 or 3.11.
- Added `server/init_db.py` script for initializing or testing the database.
- Updated README and troubleshooting guide to run `python server/init_db.py` after configuring `.env`.
- Improved `server/init_db.py` to load environment variables and support connection testing.
- Removed automatic database initialization from `server/routes/settings.py`.
- Updated README to consistently start the app with `python start.py`.

11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ source venv/bin/activate
./scripts/install.ps1
```

These scripts install the required Python packages, launch a Navidrome container so your local music is available, and attempt to install Ollama for running local models. Once complete, copy `.env.example` to `.env`, choose either OpenAI or Ollama as your language model provider, fill in the necessary keys or model name, then run `python start.py` to start the DJ.
These scripts install the required Python packages, launch a Navidrome container so your local music is available, and attempt to install Ollama for running local models. Once complete, copy `.env.example` to `.env`, choose either OpenAI or Ollama as your language model provider, fill in the necessary keys or model name, then **initialize the database** and start the DJ:

```bash
python server/init_db.py
python start.py
```

---

Expand Down Expand Up @@ -131,7 +136,7 @@ These scripts install the required Python packages, launch a Navidrome container

7. Start the application (launches the local web interface):
```bash
python server/app.py
python start.py
```

8. Access the application at `http://localhost:5000`
Expand Down Expand Up @@ -191,7 +196,7 @@ The following keys or settings are required or optional for full functionality.
Run the start script:
```bash
# If installed locally
python server/app.py
python start.py

# If using Docker
docker-compose up -d
Expand Down
5 changes: 5 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# AI DJ Troubleshooting Guide

## Initial Setup

1. Copy `.env.example` to `.env` and fill in your API keys.
2. Run `python server/init_db.py` to create the local database (use `--test` to verify the connection first if needed).

## Common Errors and Solutions

### API Key Errors (401)
Expand Down
56 changes: 56 additions & 0 deletions server/init_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Database initialization utility for AI DJ."""

import argparse
import logging
import os
import sys
from pathlib import Path

from dotenv import load_dotenv

sys.path.append(str(Path(__file__).resolve().parent))

from routes.settings import init_db, get_db_connection

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def load_environment() -> None:
"""Load environment variables from a .env file if present."""
env_path = Path(__file__).resolve().parents[1] / ".env"
if env_path.exists():
load_dotenv(env_path)

def test_connection():
"""Test database connectivity."""
try:
conn = get_db_connection()
conn.execute("SELECT 1")
conn.close()
logger.info("Database connection successful.")
return True
except Exception as e:
logger.exception("Database connection failed: %s", e)
return False


def main():
parser = argparse.ArgumentParser(description="Initialize or test the AI DJ database")
parser.add_argument("--test", action="store_true", help="Only test the database connection")
args = parser.parse_args()

load_environment()

if args.test:
test_connection()
return

try:
init_db()
logger.info("Database initialized successfully.")
except Exception as e:
logger.exception("Database initialization failed: %s", e)

if __name__ == "__main__":
main()

3 changes: 0 additions & 3 deletions server/routes/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ def init_db():
conn.commit()
conn.close()

# Initialize database when module is loaded
init_db()

# Helper functions
def get_available_voices():
"""Get list of available voices from ElevenLabs."""
Expand Down