KWK25 commited on
Commit
0c7e457
·
verified ·
1 Parent(s): 9c81112

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -19
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
- 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
  # Convert Gradio history format to API format
21
-
22
  for user_msg, bot_msg in history:
23
- messages.append({"role": "user", "content": user_msg})
24
- messages.append({"role": "assistant", "content": bot_msg})
25
 
26
- # Add latest user message
27
- messages.append({"role": "user", "content": message})
28
 
29
- #Get model response
30
- response = client.chat_completion(
31
- messages,
32
- max_tokens=150
33
- )
34
 
35
- return response['choices'][0]['message']['content'].strip()
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
  )