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