AI Mood Music Generator is a web application that analyzes text input to detect the mood and generates a Spotify playlist based on the mood and selected genres. It is built using:
I started by integrating LangChain to analyze the mood of the provided text input. Next, I used the Spotify Web API to fetch playlists that match the detected mood and selected genres. I then implemented a multi-select genre feature using ShadCN UI's Checkbox
component. The playlist results are displayed with an embedded Spotify player for users to play songs directly from the app.
Afterward, I focused on styling the application using Shadcn UI, ensuring a modern and responsive design. Lastly, I performed some small refactoring and styling touch-ups to enhance the user experience.
To run the project in your local environment, follow these steps:
npm install
or yarn
in the project directory to install the required dependencies..env.local
file in the root of the project and add your Spotify API credentials and Google API key:NEXT_PUBLIC_SPOTIFY_CLIENT_ID=your_spotify_client_id
NEXT_PUBLIC_SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
NEXT_PUBLIC_GOOGLE_API_KEY=your_google_api_key
npm run dev
or yarn dev
to start the project.import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
const model = new ChatGoogleGenerativeAI({
apiKey: process.env.NEXT_PUBLIC_GOOGLE_API_KEY,
temperature: 0.7,
model: "gemini-1.5-flash",
maxOutputTokens: 8192,
topK: 64,
topP: 0.95,
safetySettings: [
{
category: "HARM_CATEGORY_HARASSMENT",
threshold: "BLOCK_LOW_AND_ABOVE",
},
],
});
export const analyzeMood = async (text: string): Promise<string> => {
const prompt = `Analyze the mood of the following text and respond with a single word: ${text}`;
try {
const res = await model.invoke(prompt);
return res.content.trim().toLowerCase();
} catch (error) {
console.error("Error analyzing mood:", error);
throw error;
}
};