Update app.py
Browse files
app.py
CHANGED
|
@@ -7,22 +7,35 @@ st.title("🎶 Mood-Based Indian Song Player")
|
|
| 7 |
|
| 8 |
# Sidebar for user input
|
| 9 |
st.sidebar.header("Enter Your Input")
|
| 10 |
-
input_method = "Text" # Only text input is available
|
| 11 |
|
| 12 |
# Input for Gemini API key
|
| 13 |
gemini_api_key = st.sidebar.text_input("Enter your Gemini API Key:", type="password")
|
| 14 |
|
| 15 |
-
# Text input for user's mood
|
| 16 |
-
user_input = st.text_input("Enter your mood
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Function to get song recommendations using Gemini API
|
| 19 |
def get_song_recommendations(user_input, api_key):
|
| 20 |
try:
|
| 21 |
genai.configure(api_key=api_key)
|
| 22 |
model = genai.GenerativeModel('gemini-pro')
|
| 23 |
-
#
|
| 24 |
prompt = f"""
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
Output the mood followed by the song recommendations in the following format:
|
| 27 |
Mood: [mood]
|
| 28 |
1. Song Title - Artist Name
|
|
@@ -62,8 +75,9 @@ if user_input and gemini_api_key:
|
|
| 62 |
video_url = search_youtube(query)
|
| 63 |
if video_url:
|
| 64 |
st.video(video_url)
|
| 65 |
-
|
| 66 |
-
|
|
|
|
| 67 |
st.success(f"Added '{song}' to your playlist!")
|
| 68 |
else:
|
| 69 |
st.warning(f"Could not find '{song}' on YouTube.")
|
|
@@ -72,6 +86,16 @@ if user_input and gemini_api_key:
|
|
| 72 |
else:
|
| 73 |
st.warning("Please provide input to get song recommendations.")
|
| 74 |
elif not user_input:
|
| 75 |
-
st.warning("Please enter your mood
|
| 76 |
elif not gemini_api_key:
|
| 77 |
-
st.warning("Please enter your Gemini API key to get started.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Sidebar for user input
|
| 9 |
st.sidebar.header("Enter Your Input")
|
|
|
|
| 10 |
|
| 11 |
# Input for Gemini API key
|
| 12 |
gemini_api_key = st.sidebar.text_input("Enter your Gemini API Key:", type="password")
|
| 13 |
|
| 14 |
+
# Text input for user's mood and context
|
| 15 |
+
user_input = st.text_input("Enter your mood and context:",
|
| 16 |
+
placeholder="e.g., 'I'm feeling happy on a sunny day'")
|
| 17 |
+
|
| 18 |
+
# Initialize playlist in session state
|
| 19 |
+
if 'playlist' not in st.session_state:
|
| 20 |
+
st.session_state.playlist = []
|
| 21 |
|
| 22 |
# Function to get song recommendations using Gemini API
|
| 23 |
def get_song_recommendations(user_input, api_key):
|
| 24 |
try:
|
| 25 |
genai.configure(api_key=api_key)
|
| 26 |
model = genai.GenerativeModel('gemini-pro')
|
| 27 |
+
# Enhanced prompt with examples
|
| 28 |
prompt = f"""
|
| 29 |
+
Given the input: '{user_input}', determine the mood or context and suggest 3 popular Indian songs that match this mood or context, considering the specific details provided.
|
| 30 |
+
|
| 31 |
+
Examples:
|
| 32 |
+
- Input: 'I'm feeling stressed at work'
|
| 33 |
+
Mood: stressed
|
| 34 |
+
Songs: calming instrumental music
|
| 35 |
+
- Input: 'I'm excited about my vacation'
|
| 36 |
+
Mood: excited
|
| 37 |
+
Songs: upbeat and joyful songs
|
| 38 |
+
|
| 39 |
Output the mood followed by the song recommendations in the following format:
|
| 40 |
Mood: [mood]
|
| 41 |
1. Song Title - Artist Name
|
|
|
|
| 75 |
video_url = search_youtube(query)
|
| 76 |
if video_url:
|
| 77 |
st.video(video_url)
|
| 78 |
+
# Add to playlist button
|
| 79 |
+
if st.button(f"Add '{song}' to Playlist", key=f"add_{song}"):
|
| 80 |
+
st.session_state.playlist.append((song, video_url))
|
| 81 |
st.success(f"Added '{song}' to your playlist!")
|
| 82 |
else:
|
| 83 |
st.warning(f"Could not find '{song}' on YouTube.")
|
|
|
|
| 86 |
else:
|
| 87 |
st.warning("Please provide input to get song recommendations.")
|
| 88 |
elif not user_input:
|
| 89 |
+
st.warning("Please enter your mood and context.")
|
| 90 |
elif not gemini_api_key:
|
| 91 |
+
st.warning("Please enter your Gemini API key to get started.")
|
| 92 |
+
|
| 93 |
+
# Display the playlist
|
| 94 |
+
st.sidebar.header("Your Playlist")
|
| 95 |
+
if st.session_state.playlist:
|
| 96 |
+
for idx, (song, url) in enumerate(st.session_state.playlist):
|
| 97 |
+
st.sidebar.write(f"{idx + 1}. {song}")
|
| 98 |
+
if st.sidebar.button(f"Play {song}", key=f"play_{song}"):
|
| 99 |
+
st.video(url)
|
| 100 |
+
else:
|
| 101 |
+
st.sidebar.write("Your playlist is empty.")
|