Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,31 +4,33 @@ from huggingface_hub import InferenceClient
|
|
| 4 |
client = InferenceClient("microsoft/phi-4")
|
| 5 |
|
| 6 |
def respond(message, history):
|
| 7 |
-
# System prompt
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# Convert Gradio history format to API format
|
| 17 |
conversation = ""
|
| 18 |
for user_msg, bot_msg in history:
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
|
|
|
| 22 |
prompt = system_prompt + conversation
|
| 23 |
|
| 24 |
-
|
| 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 |
)
|
| 33 |
|
| 34 |
chatbot.launch()
|
|
|
|
|
|
| 4 |
client = InferenceClient("microsoft/phi-4")
|
| 5 |
|
| 6 |
def respond(message, history):
|
| 7 |
+
# System prompt to guide the model
|
| 8 |
+
system_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.\n\n"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Build conversation history into a string
|
|
|
|
| 16 |
conversation = ""
|
| 17 |
for user_msg, bot_msg in history:
|
| 18 |
+
conversation += f"User: {user_msg}\nBot: {bot_msg}\n"
|
| 19 |
+
conversation += f"User: {message}\nBot:"
|
| 20 |
|
| 21 |
+
# Combine system prompt and conversation
|
| 22 |
prompt = system_prompt + conversation
|
| 23 |
|
| 24 |
+
# Call the model using text_generation
|
| 25 |
+
response = client.text_generation(prompt, max_new_tokens=150)
|
| 26 |
+
|
| 27 |
return response.strip()
|
| 28 |
|
| 29 |
chatbot = gr.ChatInterface(
|
| 30 |
+
respond,
|
| 31 |
title="K-pop Chatbot",
|
| 32 |
description="Ask me anything about K-pop! 🎤🎶"
|
| 33 |
)
|
| 34 |
|
| 35 |
chatbot.launch()
|
| 36 |
+
|