Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
|
| 7 |
def respond(message, history):
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
"
|
| 11 |
-
"
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
)
|
| 15 |
-
|
| 16 |
-
|
| 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 |
+
|