Spaces:
Running
Running
Nathan Gebreab
commited on
Commit
·
7bf136e
1
Parent(s):
1b64026
updated with proper gradio formatting
Browse files
app.py
CHANGED
|
@@ -30,7 +30,7 @@ import gradio as gr
|
|
| 30 |
from huggingface_hub import InferenceClient
|
| 31 |
|
| 32 |
|
| 33 |
-
model_id
|
| 34 |
|
| 35 |
# Suppress warnings
|
| 36 |
warnings.filterwarnings('ignore')
|
|
@@ -139,97 +139,48 @@ def generate_response(query, num_songs):
|
|
| 139 |
|
| 140 |
return response
|
| 141 |
|
| 142 |
-
# def chatbot():
|
| 143 |
-
# print("=" * 60)
|
| 144 |
-
# print("Spot: The Spotify Chatbot")
|
| 145 |
-
# print("=" * 60)
|
| 146 |
-
# print("\nHi there! My name's Spot and I'm here to give song recommendations!")
|
| 147 |
-
# print("You can request a specific song, or you can just let me know how you're feeling and we can get started!\n")
|
| 148 |
-
# print("Examples of song requests:")
|
| 149 |
-
# print(" - 'Give me 3 songs that start with W'")
|
| 150 |
-
# print(" - 'Recommend 5 upbeat songs'")
|
| 151 |
-
# print(" - 'Show me songs by Drake'")
|
| 152 |
-
# print("\nType 'quit' or 'exit' to stop.\n")
|
| 153 |
-
|
| 154 |
-
# while True:
|
| 155 |
-
# # Get user input
|
| 156 |
-
# user_input = input("You: ").strip()
|
| 157 |
-
|
| 158 |
-
# if user_input.lower() in ['quit', 'exit', 'bye', 'goodbye']:
|
| 159 |
-
# print("\nSpot: Thanks for chatting! Goodbye!")
|
| 160 |
-
# break
|
| 161 |
-
# # elif user_input.lower() in ['test']:
|
| 162 |
-
# # test_chatbot()
|
| 163 |
-
# elif not user_input:
|
| 164 |
-
# print("Spot: Please ask me something!\n")
|
| 165 |
-
# continue
|
| 166 |
-
# else:
|
| 167 |
-
|
| 168 |
-
# num_songs = num_requested_songs(user_input)
|
| 169 |
-
|
| 170 |
-
# response = generate_response(user_input, num_songs)
|
| 171 |
-
# print(f"\nSpot: {response}")
|
| 172 |
-
# continue
|
| 173 |
-
|
| 174 |
-
# chatbot()
|
| 175 |
-
|
| 176 |
-
|
| 177 |
def respond(
|
| 178 |
message,
|
| 179 |
history: list[dict[str, str]],
|
| 180 |
-
system_message,
|
| 181 |
-
max_tokens,
|
| 182 |
-
temperature,
|
| 183 |
-
top_p,
|
| 184 |
-
hf_token: gr.OAuthToken,
|
| 185 |
):
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
messages.append({"role": "user", "content": message})
|
| 196 |
-
|
| 197 |
-
response = ""
|
| 198 |
-
|
| 199 |
-
for message in client.chat_completion(
|
| 200 |
-
messages,
|
| 201 |
-
max_tokens=max_tokens,
|
| 202 |
-
stream=True,
|
| 203 |
-
temperature=temperature,
|
| 204 |
-
top_p=top_p,
|
| 205 |
-
):
|
| 206 |
-
choices = message.choices
|
| 207 |
-
token = ""
|
| 208 |
-
if len(choices) and choices[0].delta.content:
|
| 209 |
-
token = choices[0].delta.content
|
| 210 |
-
|
| 211 |
-
response += token
|
| 212 |
-
yield response
|
| 213 |
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
-
"""
|
| 216 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 217 |
-
"""
|
| 218 |
chatbot = gr.ChatInterface(
|
| 219 |
respond,
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
|
|
|
| 232 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
)
|
| 234 |
|
| 235 |
with gr.Blocks() as demo:
|
|
|
|
| 30 |
from huggingface_hub import InferenceClient
|
| 31 |
|
| 32 |
|
| 33 |
+
model_id="meta-llama/Llama-3.2-3B-Instruct"
|
| 34 |
|
| 35 |
# Suppress warnings
|
| 36 |
warnings.filterwarnings('ignore')
|
|
|
|
| 139 |
|
| 140 |
return response
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
def respond(
|
| 143 |
message,
|
| 144 |
history: list[dict[str, str]],
|
| 145 |
+
# system_message,
|
| 146 |
+
# max_tokens,
|
| 147 |
+
# temperature,
|
| 148 |
+
# top_p,
|
| 149 |
+
# hf_token: gr.OAuthToken,
|
| 150 |
):
|
| 151 |
+
|
| 152 |
+
if message.lower() in ['quit', 'exit', 'bye', 'goodbye']:
|
| 153 |
+
return "Thanks for chatting!"
|
| 154 |
+
|
| 155 |
+
if not message.strip():
|
| 156 |
+
return "Please ask me something!"
|
| 157 |
+
|
| 158 |
+
num_songs = num_requested_songs(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
+
response = generate_response(message, num_songs)
|
| 161 |
+
return response
|
| 162 |
+
|
| 163 |
|
|
|
|
|
|
|
|
|
|
| 164 |
chatbot = gr.ChatInterface(
|
| 165 |
respond,
|
| 166 |
+
title="Spot: The Spotify Chatbot",
|
| 167 |
+
description="""
|
| 168 |
+
Hello! My name's Spot and I'm here to give song recommendations!
|
| 169 |
+
|
| 170 |
+
You can request a specific song, or just let me know how you're feeling!
|
| 171 |
+
|
| 172 |
+
*Type 'quit' or 'exit' to end the conversation.*
|
| 173 |
+
""",
|
| 174 |
+
examples=[
|
| 175 |
+
"Give me 8 upbeat songs",
|
| 176 |
+
"Show me 5 chill songs for studying",
|
| 177 |
+
"Recommend songs by Drake",
|
| 178 |
+
"I want something energetic"
|
| 179 |
],
|
| 180 |
+
theme="glass",
|
| 181 |
+
# retry_btn=None,
|
| 182 |
+
# undo_btn=None,
|
| 183 |
+
# clear_btn="Clear Chat"
|
| 184 |
)
|
| 185 |
|
| 186 |
with gr.Blocks() as demo:
|