Spaces:
Runtime error
Runtime error
turned random into general chatbot
Browse files
app.py
CHANGED
|
@@ -1,12 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import random
|
| 3 |
|
| 4 |
-
|
| 5 |
-
responses = ["yes" , "No"]
|
| 6 |
-
return random.choice(responses)
|
| 7 |
|
|
|
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
chatbot.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
client = InferenceClient("microsoft/phi-4")
|
| 6 |
|
| 7 |
+
def respond(message, history):
|
| 8 |
|
| 9 |
+
messages = [{"role": "system", "content": "you are a friendly chatbot"}]
|
| 10 |
+
|
| 11 |
+
if history:
|
| 12 |
+
messages.extend(history)
|
| 13 |
+
|
| 14 |
+
message.append({"role": "system", "content":message})
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
responses = client.chat_completion(
|
| 18 |
+
messages,
|
| 19 |
+
max_tokens=100
|
| 20 |
+
)
|
| 21 |
+
return response['choices'][0]['message']['content'].strip()
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
chatbot = gr.ChatInterface(respond, type="messages" , title="Friendly chatbot")
|
| 27 |
|
| 28 |
chatbot.launch()
|