How mdziegielewska/music-genre-classification works
Project Type and Purpose
• This is a full-stack web application built with Django (Python) that integrates a pre-trained music genre classification model.
• Users submit audio tracks, the system predicts genre and suggests similar tracks, with optional user registration to save search history.
File Structure Analysis
• Top-level:
• app/ – contains both frontend (templates, static) and backend (Django project & app) plus the ML model code.
• Presentation.pptx, README.md.
• Inside app/:
• src/ – Django project (“MGCproject”) and Django app (“MGCapp”) plus predict_genre.py entrypoint.
• src/MGCmodel/ – holds model code (cnn_music_genre_classifier.py, preprocess.py) and artifacts (trainModel.h5, data.json).
• cypress/ – end-to-end tests for the UI.
• Architectural pattern: classic Django MVC:
• Models (MGCapp/models.py), Views (MGCapp/views.py, predict_genre.py), Templates (app/src/templates).
• Static assets (app/src/static).
• Machine learning service embedded alongside backend code.
Key Components
a. Web Browser (Client)
– UI rendered via Django templates & served static assets
– Cypress test runner (E2E testing)
b. Django Web Server (Backend)
– URL router (MGCproject/urls.py) → Views (MGCapp/views.py, predict_genre.py)
– Forms & authentication flows (MGCapp/forms.py)
– ORM & Database (Django models → PostgreSQL/SQLite)
c. ML Model Service
– Prediction module (music_genre_classifier.py)
– Preprocessing (preprocess.py)
– Model file (trainModel.h5)
d. Data Store
– User, SongSearchHistory tables (managed by Django migrations)
– Static/media files (uploaded audio or images)
e. External/Deployment (optional)
– CI/CD or containerization if planned
Relationships & Data Flow
1. User submits track via Web UI → HTTP POST to Django view.
2. View invokes ML service: preprocess → load model → predict genre.
3. Prediction result returned to view → rendered in HTML → sent to client.
4. If authenticated, save search to database via ORM.
5. User requests “saved history” → view queries database → renders history page.
6. Cypress E2E tests simulate browser interactions and validate flows.
Architectural Patterns & Principles
• MVC (Model-View-Controller) with clear separation of concerns.
• “Fat view, thin template”: business logic in views/MGCmodel modules.
• Single-process ML integration; consider decoupling with a microservice in future.
• Use of Django migrations for schema evolution.
• Automated E2E testing layer (Cypress).