KWK25 commited on
Commit
d13dbb5
·
verified ·
1 Parent(s): 08681e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -27
app.py CHANGED
@@ -1,42 +1,37 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Use a Spaces-friendly chat model
5
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
  def respond(message, history):
8
- # Build K-pop specific system prompt
9
- system_prompt = (
10
- "You are a friendly chatbot who ONLY talks about K-pop. "
11
- "You are an expert in K-pop groups, idols, music, albums, choreography, fandom culture, "
12
- "and industry news. If a user asks about anything unrelated to K-pop, politely redirect "
13
- "the conversation back to K-pop.\n\n"
 
 
 
 
 
 
 
 
 
 
 
14
  )
15
-
16
- # Turn chat history into a plain text conversation
17
- conversation = ""
18
- for user_msg, bot_msg in history:
19
- conversation += f"User: {user_msg}\nBot: {bot_msg}\n"
20
- conversation += f"User: {message}\nBot:"
21
-
22
- # Combine instructions and conversation
23
- prompt = system_prompt + conversation
24
-
25
- # Generate response
26
- response = client.text_generation(
27
- prompt,
28
- max_new_tokens=150,
29
- do_sample=True,
30
- temperature=0.7
31
- )
32
-
33
- return response.strip()
34
 
35
  chatbot = gr.ChatInterface(
36
  respond,
 
37
  title="K-pop Chatbot",
38
  description="Ask me anything about K-pop! 🎤🎶"
39
  )
40
 
41
  chatbot.launch()
42
 
 
 
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
+ # 🔹 Changed system prompt to force K-pop only responses
8
+ messages = [{
9
+ "role": "system",
10
+ "content": (
11
+ "You are a friendly chatbot who ONLY talks about K-pop. "
12
+
13
+ )
14
+ }]
15
+
16
+ if history:
17
+ messages.extend(history)
18
+
19
+ messages.append({"role": "user", "content": message})
20
+
21
+ response = client.chat_completion(
22
+ messages,
23
+ max_tokens=200
24
  )
25
+
26
+ return response['choices'][0]['message']['content'].strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  chatbot = gr.ChatInterface(
29
  respond,
30
+ type="messages",
31
  title="K-pop Chatbot",
32
  description="Ask me anything about K-pop! 🎤🎶"
33
  )
34
 
35
  chatbot.launch()
36
 
37
+