Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
history
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
clear_btn = gr.Button("Clear Chat")
|
| 38 |
-
|
| 39 |
-
msg.submit(get_song_recommendation, [msg, chatbot], [msg, chatbot])
|
| 40 |
-
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
| 41 |
-
|
| 42 |
-
return demo
|
| 43 |
-
|
| 44 |
-
def page_top_genres():
|
| 45 |
-
return gr.Markdown("## 🎶 Top Genres\n- Pop\n- Rock\n- Jazz\n- Hip Hop\n- Classical")
|
| 46 |
-
|
| 47 |
-
def page_contact():
|
| 48 |
-
return gr.Markdown("## 📬 Contact\nMade with ❤️. Reach me at: [your-email@example.com]")
|
| 49 |
-
|
| 50 |
-
# --- Main App with Tabs ---
|
| 51 |
-
demo = gr.TabbedInterface(
|
| 52 |
-
interface_list=[page_home, page_about, page_chatbot, page_top_genres, page_contact],
|
| 53 |
-
tab_names=["Home", "About", "Chatbot", "Top Genres", "Contact"]
|
| 54 |
)
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
client = InferenceClient("microsoft/phi-4")
|
| 5 |
+
|
| 6 |
+
def respond(message, history):
|
| 7 |
+
# System prompt specialized for K-pop
|
| 8 |
+
messages = [
|
| 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 |
+
if history:
|
| 21 |
+
messages.extend(history)
|
| 22 |
+
|
| 23 |
+
messages.append({"role": "user", "content": message})
|
| 24 |
+
|
| 25 |
+
response = client.chat_completion(
|
| 26 |
+
messages,
|
| 27 |
+
max_tokens=150
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
return response['choices'][0]['message']['content'].strip()
|
| 31 |
+
|
| 32 |
+
chatbot = gr.ChatInterface(
|
| 33 |
+
respond,
|
| 34 |
+
type="messages",
|
| 35 |
+
title="K-pop Chatbot",
|
| 36 |
+
description="Ask me anything about K-pop! 🎤🎶"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
)
|
| 38 |
|
| 39 |
+
chatbot.launch()
|
|
|