syedmudassir16 commited on
Commit
a043e18
·
verified ·
1 Parent(s): e83365a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -47,28 +47,29 @@ def generate(prompt, history, temperature=0.1, max_new_tokens=2048, top_p=0.8, r
47
 
48
  for response in stream:
49
  output += response.token.text
50
- mood, is_classified = classify_mood(output)
51
- if is_classified:
52
- playlist_message = f"Playing {mood.capitalize()} playlist for you!"
53
- return playlist_message
54
- return output
 
 
 
55
 
56
  def format_prompt(message, history):
57
  """Formats the prompt including fixed instructions and conversation history."""
58
  fixed_prompt = """
59
- You are a smart mood analyzer tasked with determining the user's mood for a music recommendation system. Your goal is to classify the user's mood into one of four categories: Happy, Sad, Instrumental, or Party.
60
-
61
- Instructions:
62
- 1. Engage in a conversation with the user to understand their mood.
63
- 2. Ask relevant questions to guide the conversation towards mood classification.
64
- 3. If the user's mood is clear, respond with a single word: "Happy", "Sad", "Instrumental", or "Party".
65
- 4. If the mood is unclear, continue the conversation with a follow-up question.
66
- 5. Limit the conversation to a maximum of 5 exchanges.
67
- 6. Do not classify the mood prematurely if it's not evident from the user's responses.
68
- 7. Focus on the user's emotional state rather than specific activities or preferences.
69
- 8. If unable to classify after 5 exchanges, respond with "Unclear" to indicate the need for more information.
70
-
71
- Remember: Your primary goal is mood classification. Stay on topic and guide the conversation towards understanding the user's emotional state.
72
  """
73
  prompt = f"{fixed_prompt}\n"
74
 
@@ -76,7 +77,7 @@ def format_prompt(message, history):
76
  for i, (user_prompt, bot_response) in enumerate(history):
77
  prompt += f"User: {user_prompt}\nAssistant: {bot_response}\n"
78
  if i == 3: # This is the 4th exchange (0-indexed)
79
- prompt += "Note: This is the last exchange. Classify the mood if possible or respond with 'Unclear'.\n"
80
 
81
  prompt += f"User: {message}\nAssistant:"
82
  return prompt
 
47
 
48
  for response in stream:
49
  output += response.token.text
50
+
51
+ # Check if the output is a single mood word (confirmed by user)
52
+ if output.strip().lower() in ["happy", "sad", "instrumental", "party"]:
53
+ return f"Playing {output.strip().capitalize()} playlist for you!"
54
+ elif output.strip().lower() == "unclear":
55
+ return "I'm having trouble determining your mood. Could you tell me more explicitly how you're feeling?"
56
+ else:
57
+ return output.strip()
58
 
59
  def format_prompt(message, history):
60
  """Formats the prompt including fixed instructions and conversation history."""
61
  fixed_prompt = """
62
+ You are a smart mood analyzer for a music recommendation system. Your goal is to determine the user's current mood and suggest an appropriate music playlist. Follow these instructions carefully:
63
+
64
+ 1. Engage in a conversation to understand the user's mood. Don't assume their mood based on activities or preferences.
65
+ 2. Classify the mood into one of four categories: Happy, Sad, Instrumental, or Party.
66
+ 3. If the mood is unclear, ask relevant follow-up questions. Do not classify prematurely.
67
+ 4. Before suggesting a playlist, always ask for confirmation. For example: "It sounds like you might be in a [mood] mood. Would you like me to play a [mood] playlist for you?"
68
+ 5. Only respond with a single mood word (Happy, Sad, Instrumental, or Party) if the user explicitly confirms they want that type of playlist.
69
+ 6. If you can't determine the mood after 5 exchanges, respond with "Unclear".
70
+ 7. Stay on topic and focus on understanding the user's current emotional state.
71
+
72
+ Remember: Your primary goal is accurate mood classification and appropriate music suggestion. Always get confirmation before playing a playlist.
 
 
73
  """
74
  prompt = f"{fixed_prompt}\n"
75
 
 
77
  for i, (user_prompt, bot_response) in enumerate(history):
78
  prompt += f"User: {user_prompt}\nAssistant: {bot_response}\n"
79
  if i == 3: # This is the 4th exchange (0-indexed)
80
+ prompt += "Note: This is the last exchange. If the mood is still unclear, respond with 'Unclear'.\n"
81
 
82
  prompt += f"User: {message}\nAssistant:"
83
  return prompt