Akshayram1 commited on
Commit
3e39397
·
verified ·
1 Parent(s): d1abf9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -31,11 +31,11 @@ def convert_audio_to_wav(audio_bytes):
31
  def detect_mood(text):
32
  result = mood_classifier(text)[0]
33
  if result['label'] == 'POSITIVE':
34
- return "joyful"
35
  elif result['label'] == 'NEGATIVE':
36
  return "sad"
37
  else:
38
- return "neutral"
39
 
40
  def speech_to_text():
41
  # Initialize recognizer
@@ -130,8 +130,14 @@ user_text = None
130
 
131
  if input_method == "Text":
132
  # Text input
133
- user_mood = st.sidebar.selectbox("Select your mood:", mood_options)
134
- user_text = user_mood
 
 
 
 
 
 
135
  else:
136
  # Speech input
137
  st.write("📢 Click the button below and tell me about your day...")
@@ -147,12 +153,11 @@ if 'playlist' not in st.session_state:
147
  st.session_state.playlist = []
148
 
149
  # Main content
150
- if user_text and gemini_api_key:
151
- detected_mood = detect_mood(user_text)
152
- st.write(f"🎭 Detected Mood: **{detected_mood}**")
153
 
154
  st.write("🎵 Recommended Songs:")
155
- recommendations = get_song_recommendations(detected_mood, gemini_api_key)
156
  if recommendations:
157
  st.write(recommendations)
158
 
 
31
  def detect_mood(text):
32
  result = mood_classifier(text)[0]
33
  if result['label'] == 'POSITIVE':
34
+ return "happy"
35
  elif result['label'] == 'NEGATIVE':
36
  return "sad"
37
  else:
38
+ return "calm"
39
 
40
  def speech_to_text():
41
  # Initialize recognizer
 
130
 
131
  if input_method == "Text":
132
  # Text input
133
+ user_text = st.sidebar.text_input("Enter text describing your mood:")
134
+ if st.sidebar.button("Submit"):
135
+ if user_text:
136
+ user_mood = detect_mood(user_text)
137
+ st.write(f"Based on your text, I detect your mood as: **{user_mood}**")
138
+ else:
139
+ st.sidebar.warning("Please enter your mood description.")
140
+ user_mood = None
141
  else:
142
  # Speech input
143
  st.write("📢 Click the button below and tell me about your day...")
 
153
  st.session_state.playlist = []
154
 
155
  # Main content
156
+ if user_mood and gemini_api_key:
157
+ st.write(f"🎭 Detected Mood: **{user_mood}**")
 
158
 
159
  st.write("🎵 Recommended Songs:")
160
+ recommendations = get_song_recommendations(user_mood, gemini_api_key)
161
  if recommendations:
162
  st.write(recommendations)
163