File size: 2,203 Bytes
19f6f7b
882870f
ba60aee
b93b0d7
 
 
 
 
 
 
 
 
 
 
 
 
 
ba60aee
882870f
b7cea67
22d72c6
2af61a3
ba60aee
 
22d72c6
882870f
71b8a57
ba60aee
 
 
19f6f7b
882870f
f8aa260
88c42c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4519c6
 
 
88c42c8
e4519c6
88c42c8
 
 
 
 
 
 
 
 
 
e4519c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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()