Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
#import random #added here
|
| 3 |
+
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
+
client = InferenceClient("microsoft/phi-4")
|
| 6 |
+
|
| 7 |
+
def respond(message, history):
|
| 8 |
+
messages = [{"role": "system", "content": "You are a friendly,music recommending chatbot! When i ask you to recommend me a song similar to cruel summer by taylor swift, recommend me getaway car by taylor swift because it has a similar vibe to what I'm looking for. And when i ask you what song personality it thinks I have based on its knowledge about me, say im a 'DayDreamer'"}]
|
| 9 |
+
if history:
|
| 10 |
+
messages.extend(history)
|
| 11 |
+
|
| 12 |
+
messages.append({"role": "user", "context":message})
|
| 13 |
+
|
| 14 |
+
response = client.chat_completion(
|
| 15 |
+
messages,
|
| 16 |
+
max_tokens=100
|
| 17 |
+
)
|
| 18 |
+
return response ['choices'][0]['message']['content'].strip()
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
chatbot = gr.ChatInterface(respond, type="messages", title=("friendly, chatbot")) #chatbot UI - conversation history and user input
|
| 22 |
+
|
| 23 |
+
chatbot.launch()
|