Spaces:
Sleeping
Sleeping
Update app.py
Browse filesturned echo into friendly chatbot
app.py
CHANGED
|
@@ -1,8 +1,24 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
return message
|
| 5 |
|
| 6 |
-
chatbot = gr.ChatInterface(echo) #chatbot UI = conversation history and user input
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
# import random
|
| 3 |
+
from huggingface_hub import InterenceClient as ic
|
| 4 |
|
| 5 |
+
client = ic("microsoft/phi-4")
|
|
|
|
| 6 |
|
|
|
|
| 7 |
|
| 8 |
+
def respond(message, history):
|
| 9 |
+
|
| 10 |
+
messages = [{"role": "system", "content: "You are a friendly chatbot!}]
|
| 11 |
+
|
| 12 |
+
if history:
|
| 13 |
+
messages.extend(history)
|
| 14 |
+
|
| 15 |
+
messages.append({"role": "user", "content": message})
|
| 16 |
+
|
| 17 |
+
response = client.chat_completion(messages, max_token = 100)
|
| 18 |
+
|
| 19 |
+
return response['choices'][0]['message']['content'].strip()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
chatbot = gr.ChatInterface(respond, type = 'messages', title = 'Friendly Chatbot') #chatbot UI = conversation history and user input
|
| 23 |
+
|
| 24 |
+
chatbot.launch()
|