Spaces:
Runtime error
Runtime error
changed random yes/no chatbot into general chatbot
Browse filesturned that chatbot of random choices into more dynamic conversation, added token to access model.
app.py
CHANGED
|
@@ -1,12 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
|
| 5 |
-
responses = ["Yes", "No"]
|
| 6 |
-
return random.choice(responses)
|
| 7 |
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# chatbot UI - conversation history and user input
|
| 11 |
|
| 12 |
chatbot.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
client = InferenceClient("microsoft/phi-4")
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def respond(message,history): #function to return the history of messages sent
|
| 7 |
+
messages[{"role": "system", "content": "You are a friendly chatbot!"}]
|
| 8 |
|
| 9 |
+
if history:
|
| 10 |
+
messages.extend(history)
|
| 11 |
+
|
| 12 |
+
messages.append({"role": "user", "content":message})
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
responses = client.chat_completion(
|
| 16 |
+
messages,
|
| 17 |
+
max_token = 568
|
| 18 |
+
)
|
| 19 |
+
return response['choices'][0]['message']['content'].strip()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
chatbot = gr.ChatInterface(respond, type="messages", title = "Friendly chatbot")
|
| 23 |
# chatbot UI - conversation history and user input
|
| 24 |
|
| 25 |
chatbot.launch()
|