Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def respond(message, history):
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
if history:
|
| 11 |
messages.extend(history)
|
| 12 |
-
|
| 13 |
messages.append({"role": "user", "content": message})
|
| 14 |
|
|
|
|
| 15 |
response = client.chat_completion(
|
| 16 |
-
messages,
|
| 17 |
max_tokens=100
|
| 18 |
)
|
| 19 |
|
| 20 |
-
return response[
|
| 21 |
|
| 22 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 23 |
|
| 24 |
-
chatbot.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Hugging Face token (create one at https://huggingface.co/settings/tokens)
|
| 5 |
+
HF_TOKEN = "MY_TOKENN"
|
| 6 |
+
|
| 7 |
+
# Pass the token so it uses the Hugging Face API instead of Nebius
|
| 8 |
+
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct-1M", token=HF_TOKEN)
|
| 9 |
|
| 10 |
def respond(message, history):
|
| 11 |
+
messages = [
|
| 12 |
+
{
|
| 13 |
+
"role": "system",
|
| 14 |
+
"content": (
|
| 15 |
+
"You are a friendly, music-recommending chatbot! "
|
| 16 |
+
"When I ask you to recommend me a song similar to 'Cruel Summer' by Taylor Swift, "
|
| 17 |
+
"recommend me 'Getaway Car' by Taylor Swift because it has a similar vibe. "
|
| 18 |
+
"When I ask you what song personality you think I have based on your knowledge about me, "
|
| 19 |
+
"say I'm a 'DayDreamer'."
|
| 20 |
+
)
|
| 21 |
+
}
|
| 22 |
+
]
|
| 23 |
|
| 24 |
if history:
|
| 25 |
messages.extend(history)
|
| 26 |
+
|
| 27 |
messages.append({"role": "user", "content": message})
|
| 28 |
|
| 29 |
+
# Pass messages as a keyword argument
|
| 30 |
response = client.chat_completion(
|
| 31 |
+
messages=messages,
|
| 32 |
max_tokens=100
|
| 33 |
)
|
| 34 |
|
| 35 |
+
return response["choices"][0]["message"]["content"].strip()
|
| 36 |
|
| 37 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 38 |
|
| 39 |
+
chatbot.launch()
|