yesnobot to gen chatbot
Browse files
app.py
CHANGED
|
@@ -1,17 +1,22 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
from huggingface_hub import InferenceClient
|
| 4 |
client = InferenceClient("microsoft/phi-4")
|
| 5 |
def respond(message, history):
|
|
|
|
| 6 |
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
|
|
|
| 7 |
if history:
|
| 8 |
-
messages.extend(
|
|
|
|
| 9 |
messages.append({"role": "user", "content": message})
|
|
|
|
| 10 |
response = client.chat_completion(
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
)
|
|
|
|
| 14 |
return response['choices'][0]['message']['content'].strip()
|
| 15 |
-
|
| 16 |
-
chatbot = gr.ChatInterface(respond, type
|
| 17 |
-
|
|
|
|
|
|
| 1 |
+
iimport gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
client = InferenceClient("microsoft/phi-4")
|
| 4 |
def respond(message, history):
|
| 5 |
+
|
| 6 |
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 7 |
+
|
| 8 |
if history:
|
| 9 |
+
messages.extend(history)
|
| 10 |
+
|
| 11 |
messages.append({"role": "user", "content": message})
|
| 12 |
+
|
| 13 |
response = client.chat_completion(
|
| 14 |
+
messages,
|
| 15 |
+
max_tokens=100
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
return response['choices'][0]['message']['content'].strip()
|
| 19 |
+
|
| 20 |
+
chatbot = gr.ChatInterface(respond, type="messages")
|
| 21 |
+
|
| 22 |
+
chatbot.launch()
|