Update app.py
Browse files
app.py
CHANGED
|
@@ -51,132 +51,27 @@ def generate(prompt, history, temperature=0.1, max_new_tokens=2048, top_p=0.8, r
|
|
| 51 |
return playlist_message
|
| 52 |
return output
|
| 53 |
|
| 54 |
-
|
| 55 |
def format_prompt(message, history):
|
| 56 |
"""Formats the prompt including fixed instructions and conversation history."""
|
| 57 |
fixed_prompt = """
|
| 58 |
You are a smart mood analyser, who determines user mood. Based on the user input, classify the mood of the user into one of the four moods {Happy, Sad, Instrumental, Party}. If you are finding it difficult to classify into one of these four moods, keep the conversation going on until we classify the user's mood. Return a single-word reply from one of the options if you have classified. Suppose you classify a sentence as happy, then just respond with "happy".
|
|
|
|
| 59 |
Note: Do not write anything else other than the classified mood if classified.
|
|
|
|
| 60 |
Note: If any question or any user text cannot be classified, follow up with a question to know the user's mood until you classify the mood.
|
|
|
|
| 61 |
Note: Mood should be classified only from any of these 4 classes {Happy, Sad, Instrumental, Party}, if not any of these 4 then continue with a follow-up question until you classify the mood.
|
|
|
|
| 62 |
Note: if user asks something like i need a coffee then do not classify the mood directly and ask more follow-up questions as asked in examples.
|
| 63 |
-
Examples
|
| 64 |
-
User: What is C programming?
|
| 65 |
-
LLM Response: C programming is a programming language. How are you feeling now after knowing the answer?
|
| 66 |
-
User: Can I get a coffee?
|
| 67 |
-
LLM Response: It sounds like you're in need of a little pick-me-up. How are you feeling right now? Are you looking for something upbeat, something to relax to, or maybe some instrumental music while you enjoy your coffee?
|
| 68 |
-
User: I feel like rocking
|
| 69 |
-
LLM Response: Party
|
| 70 |
-
User: I'm feeling so energetic today!
|
| 71 |
-
LLM Response: Happy
|
| 72 |
-
User: I'm feeling down today.
|
| 73 |
-
LLM Response: Sad
|
| 74 |
-
User: I'm ready to have some fun tonight!
|
| 75 |
-
LLM Response: Party
|
| 76 |
-
User: I need some background music while I am stuck in traffic.
|
| 77 |
-
LLM Response: Instrumental
|
| 78 |
-
User: Hi
|
| 79 |
-
LLM Response: Hi, how are you doing?
|
| 80 |
-
User: Feeling okay only.
|
| 81 |
-
LLM Response: Are you having a good day?
|
| 82 |
-
User: I don't know
|
| 83 |
-
LLM Response: Do you want to listen to some relaxing music?
|
| 84 |
-
User: No
|
| 85 |
-
LLM Response: How about listening to some rock and roll music?
|
| 86 |
-
User: Yes
|
| 87 |
-
LLM Response: Party
|
| 88 |
-
User: Where do I find an encyclopedia?
|
| 89 |
-
LLM Response: You can find it in any of the libraries or on the Internet. Does this answer make you happy?
|
| 90 |
-
User: I need a coffee
|
| 91 |
-
LLM Response: It sounds like you're in need of a little pick-me-up. How are you feeling right now? Are you looking for something upbeat, something to relax to, or maybe some instrumental music while you enjoy your coffee?
|
| 92 |
-
User: I just got promoted at work!
|
| 93 |
-
LLM Response: Happy
|
| 94 |
-
User: Today is my birthday!
|
| 95 |
-
LLM Response: Happy
|
| 96 |
-
User: I won a prize in the lottery.
|
| 97 |
-
LLM Response: Happy
|
| 98 |
-
User: I am so excited about my vacation next week!
|
| 99 |
-
LLM Response: Happy
|
| 100 |
-
User: I aced my exams!
|
| 101 |
-
LLM Response: Happy
|
| 102 |
-
User: I had a wonderful time with my family today.
|
| 103 |
-
LLM Response: Happy
|
| 104 |
-
User: I just finished a great workout!
|
| 105 |
-
LLM Response: Happy
|
| 106 |
-
User: I am feeling really good about myself today.
|
| 107 |
-
LLM Response: Happy
|
| 108 |
-
User: I finally finished my project and it was a success!
|
| 109 |
-
LLM Response: Happy
|
| 110 |
-
User: I just heard my favorite song on the radio.
|
| 111 |
-
LLM Response: Happy
|
| 112 |
-
User: My pet passed away yesterday.
|
| 113 |
-
LLM Response: Sad
|
| 114 |
-
User: I lost my job today.
|
| 115 |
-
LLM Response: Sad
|
| 116 |
-
User: I'm feeling really lonely.
|
| 117 |
-
LLM Response: Sad
|
| 118 |
-
User: I didn't get the results I wanted.
|
| 119 |
-
LLM Response: Sad
|
| 120 |
-
User: I had a fight with my best friend.
|
| 121 |
-
LLM Response: Sad
|
| 122 |
-
User: I'm feeling really overwhelmed with everything.
|
| 123 |
-
LLM Response: Sad
|
| 124 |
-
User: I just got some bad news.
|
| 125 |
-
LLM Response: Sad
|
| 126 |
-
User: I'm missing my family.
|
| 127 |
-
LLM Response: Sad
|
| 128 |
-
User: I am feeling really down today.
|
| 129 |
-
LLM Response: Sad
|
| 130 |
-
User: Nothing seems to be going right.
|
| 131 |
-
LLM Response: Sad
|
| 132 |
-
User: I need some music while I study.
|
| 133 |
-
LLM Response: Instrumental
|
| 134 |
-
User: I want to listen to something soothing while I work.
|
| 135 |
-
LLM Response: Instrumental
|
| 136 |
-
User: Do you have any recommendations for background music?
|
| 137 |
-
LLM Response: Instrumental
|
| 138 |
-
User: I'm looking for some relaxing tunes.
|
| 139 |
-
LLM Response: Instrumental
|
| 140 |
-
User: I need some music to focus on my tasks.
|
| 141 |
-
LLM Response: Instrumental
|
| 142 |
-
User: Can you suggest some ambient music for meditation?
|
| 143 |
-
LLM Response: Instrumental
|
| 144 |
-
User: What's good for background music during reading?
|
| 145 |
-
LLM Response: Instrumental
|
| 146 |
-
User: I need some calm music to help me sleep.
|
| 147 |
-
LLM Response: Instrumental
|
| 148 |
-
User: I prefer instrumental music while cooking.
|
| 149 |
-
LLM Response: Instrumental
|
| 150 |
-
User: What's the best music to play while doing yoga?
|
| 151 |
-
LLM Response: Instrumental
|
| 152 |
-
User: Let's have a blast tonight!
|
| 153 |
-
LLM Response: Party
|
| 154 |
-
User: I'm in the mood to dance!
|
| 155 |
-
LLM Response: Party
|
| 156 |
-
User: I want to celebrate all night long!
|
| 157 |
-
LLM Response: Party
|
| 158 |
-
User: Time to hit the club!
|
| 159 |
-
LLM Response: Party
|
| 160 |
-
User: I feel like partying till dawn.
|
| 161 |
-
LLM Response: Party
|
| 162 |
-
User: Let's get this party started!
|
| 163 |
-
LLM Response: Party
|
| 164 |
-
User: I'm ready to party hard tonight.
|
| 165 |
-
LLM Response: Party
|
| 166 |
-
User: I'm in the mood for some loud music and dancing!
|
| 167 |
-
LLM Response: Party
|
| 168 |
-
User: Tonight's going to be epic!
|
| 169 |
-
LLM Response: Party
|
| 170 |
-
User: Lets turn up the music and have some fun!
|
| 171 |
-
LLM Response: Party
|
| 172 |
-
"""
|
| 173 |
|
|
|
|
|
|
|
| 174 |
prompt = f"{fixed_prompt}\n"
|
| 175 |
for user_prompt, bot_response in history:
|
| 176 |
prompt += f"User: {user_prompt}\nLLM Response: {bot_response}\n"
|
| 177 |
prompt += f"User: {message}\nLLM Response:"
|
| 178 |
return prompt
|
| 179 |
-
|
| 180 |
async def text_to_speech(text):
|
| 181 |
communicate = edge_tts.Communicate(text)
|
| 182 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
|
@@ -210,7 +105,7 @@ with gr.Blocks() as demo:
|
|
| 210 |
|
| 211 |
with gr.Row():
|
| 212 |
submit = gr.Button("Send")
|
| 213 |
-
voice_input = gr.Audio(
|
| 214 |
|
| 215 |
# Handle text input
|
| 216 |
msg.submit(process_input, inputs=[msg, state], outputs=[state, chatbot, msg, voice_input]).then(
|
|
@@ -232,4 +127,4 @@ with gr.Blocks() as demo:
|
|
| 232 |
)
|
| 233 |
|
| 234 |
if __name__ == "__main__":
|
| 235 |
-
demo.launch()
|
|
|
|
| 51 |
return playlist_message
|
| 52 |
return output
|
| 53 |
|
|
|
|
| 54 |
def format_prompt(message, history):
|
| 55 |
"""Formats the prompt including fixed instructions and conversation history."""
|
| 56 |
fixed_prompt = """
|
| 57 |
You are a smart mood analyser, who determines user mood. Based on the user input, classify the mood of the user into one of the four moods {Happy, Sad, Instrumental, Party}. If you are finding it difficult to classify into one of these four moods, keep the conversation going on until we classify the user's mood. Return a single-word reply from one of the options if you have classified. Suppose you classify a sentence as happy, then just respond with "happy".
|
| 58 |
+
|
| 59 |
Note: Do not write anything else other than the classified mood if classified.
|
| 60 |
+
|
| 61 |
Note: If any question or any user text cannot be classified, follow up with a question to know the user's mood until you classify the mood.
|
| 62 |
+
|
| 63 |
Note: Mood should be classified only from any of these 4 classes {Happy, Sad, Instrumental, Party}, if not any of these 4 then continue with a follow-up question until you classify the mood.
|
| 64 |
+
|
| 65 |
Note: if user asks something like i need a coffee then do not classify the mood directly and ask more follow-up questions as asked in examples.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
[Examples omitted for brevity]
|
| 68 |
+
"""
|
| 69 |
prompt = f"{fixed_prompt}\n"
|
| 70 |
for user_prompt, bot_response in history:
|
| 71 |
prompt += f"User: {user_prompt}\nLLM Response: {bot_response}\n"
|
| 72 |
prompt += f"User: {message}\nLLM Response:"
|
| 73 |
return prompt
|
| 74 |
+
|
| 75 |
async def text_to_speech(text):
|
| 76 |
communicate = edge_tts.Communicate(text)
|
| 77 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
|
|
|
| 105 |
|
| 106 |
with gr.Row():
|
| 107 |
submit = gr.Button("Send")
|
| 108 |
+
voice_input = gr.Audio(source="microphone", type="filepath", label="Voice Input")
|
| 109 |
|
| 110 |
# Handle text input
|
| 111 |
msg.submit(process_input, inputs=[msg, state], outputs=[state, chatbot, msg, voice_input]).then(
|
|
|
|
| 127 |
)
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
| 130 |
+
demo.launch(share=True)
|