import gradio as gr import random as r from huggingface_hub import InferenceClient import pandas as pd import numpy as np import gradio as gr from sklearn.metrics.pairwise import euclidean_distances import openai # --- Set your OpenAI API key --- openai.api_key = "MY_TOKENN" # replace with your key # --- Load your CSV --- # Ensure your CSV has columns: 'song', 'artist', 'bpm', 'nrgy', 'dnce', 'dB', 'live', 'val', 'dur', 'acous', 'spch', 'pop' df = pd.read_csv("datalab_export_2025-08-11 14_16_35.csv") feature_cols = ['bpm', 'nrgy', 'dnce', 'dB', 'live', 'val', 'dur', 'acous', 'spch', 'pop'] df_features = df[feature_cols].astype(float) client = InferenceClient("microsoft/phi-4") def respond(message, history): messages = [{"role": "system", "content": "You are a friendly, music recommendation chatbot. When I ask you for a song similar to 'David by Lorde', recommend me 'The Greatest by Billie Eilish' for the simialar vibes and sound profile. When I ask you for a song similar to 'Iris by the Goo Goo Dolls', recommend me 'Look After You by The Fray' because they have similar lyrics and message of the song. When I ask you what my 'song personality type' is, tell me im an 'Hearty Dreamer ❤️'"}] if history: messages.extend(history) messages.append({"role": "user", "content": message}) response = client.chat_completion( messages, max_tokens=100 ) return response['choices'][0]['message']['content'].strip() custom_css = """ body { background-color: #3D1F4E; /* Dark purple */ } .gradio-container { background: linear-gradient(90deg, #F6A15D, #E64671, #A34087, #6C3D7C, #3D1F4E); color: white; } .chatbot { background-color: rgba(255, 255, 255, 0.1); } button { background-color: #E64671 !important; color: white !important; } /* Force the small message box to stay black */ textarea, input[type="text"] { background-color: black !important; color: white !important; border: 1px solid #A34087 !important; /* Optional: border in palette */ } """ chatbot = gr.ChatInterface( respond, type="messages", title="🎶Music Recommendation Chatbot🎶", css=custom_css ) chatbot.launch()