Skip to content

emretterzi/Api-Genre-Controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Genre Prediction API

This repository contains a Flask-based API for predicting the genre of a song based on its lyrics. The API utilizes a pre-trained machine learning model to perform genre predictions.

Features

  • Predict Genre: Send a POST request with song lyrics, and receive a predicted genre in response.
  • Pre-trained Model: The API uses a pre-trained model to provide quick and accurate genre predictions.

Getting Started

Prerequisites

Make sure you have the following installed:

  • Python 3.6 or later
  • Flask
  • joblib

You can install the required Python packages using pip:

pip install Flask joblib

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/genre-prediction-api.git
cd genre-prediction-api
  1. Place your trained model file (trained_model.joblib) in the project directory. Ensure the model file path in the code matches the location where you place your model.

Usage

  1. Run the Flask application:
python app.py
  1. The API will be accessible at http://127.0.0.1:5000.

API Endpoint

Predict Genre

  • URL: /predict

  • Method: POST

  • Request Body: JSON object containing the song lyrics.

    {
      "lyrics": "Your song lyrics here"
    }
  • Response: JSON object containing the predicted genre.

    {
      "predicted_genre": "The predicted genre"
    }

Example Request

Use curl or any HTTP client to send a POST request to the API:

curl -X POST http://127.0.0.1:5000/predict -H "Content-Type: application/json" -d '{"lyrics": "your song lyrics here"}'

Example Response

{
  "predicted_genre": "The predicted genre"
}

Error Handling

  • If the lyrics are not provided in the request, the API responds with a 400 Bad Request status and an error message:

    {
      "error": "Lyrics not provided"
    }
  • If the model file is not found, the API responds with a 500 Internal Server Error status and an error message:

    {
      "error": "Model file not found. Make sure to train the model first."
    }

Model Training

To train your own model, you need to prepare a dataset of song lyrics with their corresponding genres. You can use various machine learning libraries such as scikit-learn to train your model and save it using joblib. Ensure the saved model is named trained_model.joblib and placed in the project directory.

Screenshots

Eminem Rap-God

image

Ice-T -6 'N the Mornin!

image

About

This repository hosts a Flask-based API for predicting the genre of a song based on its lyrics. Utilizing a pre-trained machine learning model, the API provides quick and accurate genre predictions. Simply send a POST request with the song lyrics, and the API will return the predicted genre.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages