Spaces:
Sleeping
Sleeping
syedmudassir16
commited on
Update app.py
Browse files
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 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
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
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
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.
|
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
|