Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,38 +5,28 @@ client = InferenceClient("microsoft/phi-4")
|
|
| 5 |
|
| 6 |
def respond(message, history):
|
| 7 |
# System prompt specialized for K-pop
|
| 8 |
-
|
| 9 |
-
{
|
| 10 |
-
"role": "system",
|
| 11 |
-
"content": (
|
| 12 |
"You are a friendly chatbot who ONLY talks about K-pop. "
|
| 13 |
"You are an expert in K-pop groups, idols, music, albums, choreography, fandom culture, "
|
| 14 |
"and industry news. If a user asks about anything unrelated to K-pop, politely redirect "
|
| 15 |
"the conversation back to K-pop."
|
| 16 |
)
|
| 17 |
-
|
| 18 |
-
]
|
| 19 |
|
| 20 |
# Convert Gradio history format to API format
|
| 21 |
-
|
| 22 |
for user_msg, bot_msg in history:
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
| 27 |
-
messages.append({"role": "user", "content": message})
|
| 28 |
|
| 29 |
-
|
| 30 |
-
response = client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=150
|
| 33 |
-
)
|
| 34 |
|
| 35 |
-
return response
|
| 36 |
|
| 37 |
chatbot = gr.ChatInterface(
|
| 38 |
-
respond,
|
| 39 |
-
type="messages",
|
| 40 |
title="K-pop Chatbot",
|
| 41 |
description="Ask me anything about K-pop! 🎤🎶"
|
| 42 |
)
|
|
|
|
| 5 |
|
| 6 |
def respond(message, history):
|
| 7 |
# System prompt specialized for K-pop
|
| 8 |
+
sytem_prompt = (
|
|
|
|
|
|
|
|
|
|
| 9 |
"You are a friendly chatbot who ONLY talks about K-pop. "
|
| 10 |
"You are an expert in K-pop groups, idols, music, albums, choreography, fandom culture, "
|
| 11 |
"and industry news. If a user asks about anything unrelated to K-pop, politely redirect "
|
| 12 |
"the conversation back to K-pop."
|
| 13 |
)
|
| 14 |
+
|
|
|
|
| 15 |
|
| 16 |
# Convert Gradio history format to API format
|
| 17 |
+
conversation = ""
|
| 18 |
for user_msg, bot_msg in history:
|
| 19 |
+
conversatio += f"User {user_msg}\nBot: {bot_msg}\n"
|
| 20 |
+
conversation += f"User: {message}\nBot:"
|
| 21 |
|
| 22 |
+
prompt = system_prompt + conversation
|
|
|
|
| 23 |
|
| 24 |
+
response = client.text_generation(prompt, max_new_tokens=150)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
return response.strip()
|
| 27 |
|
| 28 |
chatbot = gr.ChatInterface(
|
| 29 |
+
respond,
|
|
|
|
| 30 |
title="K-pop Chatbot",
|
| 31 |
description="Ask me anything about K-pop! 🎤🎶"
|
| 32 |
)
|