Spaces:
Running
Running
Zamira1235
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from sentence_transformers import SentenceTransformer, util
|
3 |
import openai
|
4 |
import os
|
|
|
5 |
|
6 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
7 |
|
@@ -108,11 +109,14 @@ def recommend_songs_based_on_mood(mood):
|
|
108 |
"Song E"
|
109 |
]
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
116 |
def query_model(user_query):
|
117 |
"""
|
118 |
Process a user's query, find relevant information, and generate a response.
|
@@ -123,7 +127,9 @@ def query_model(user_query):
|
|
123 |
# Example logic to identify if the user query is related to song recommendations based on mood
|
124 |
if "recommend" in user_query.lower() and ("song" in user_query.lower() or "music" in user_query.lower()):
|
125 |
mood = user_query.lower().split("recommend", 1)[1].strip() # Extract mood from query
|
126 |
-
|
|
|
|
|
127 |
else:
|
128 |
relevant_segment = find_relevant_segment(user_query, segments)
|
129 |
if not relevant_segment:
|
|
|
2 |
from sentence_transformers import SentenceTransformer, util
|
3 |
import openai
|
4 |
import os
|
5 |
+
import random
|
6 |
|
7 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
8 |
|
|
|
109 |
"Song E"
|
110 |
]
|
111 |
|
112 |
+
if mood in songs_by_mood:
|
113 |
+
song = random.choice(songs_by_mood[mood]["description"])
|
114 |
+
topic = songs_by_mood[mood]["topic"]
|
115 |
+
description = f"Topic: {topic}\nDescription: Include these songs: {', '.join(songs_by_mood[mood]['description'])}"
|
116 |
+
return {"song": song, "description": description}
|
117 |
+
else:
|
118 |
+
return {"error": "Mood not recognized"}
|
119 |
+
|
120 |
def query_model(user_query):
|
121 |
"""
|
122 |
Process a user's query, find relevant information, and generate a response.
|
|
|
127 |
# Example logic to identify if the user query is related to song recommendations based on mood
|
128 |
if "recommend" in user_query.lower() and ("song" in user_query.lower() or "music" in user_query.lower()):
|
129 |
mood = user_query.lower().split("recommend", 1)[1].strip() # Extract mood from query
|
130 |
+
recommendation = recommend_songs_based_on_mood(mood)
|
131 |
+
if "error" in recommendation:
|
132 |
+
response = recommendation["error"]
|
133 |
else:
|
134 |
relevant_segment = find_relevant_segment(user_query, segments)
|
135 |
if not relevant_segment:
|