Spaces:
Sleeping
Sleeping
Amanda Sackey
commited on
turned random into general chatbot
Browse filesturned random into general chatbot into more dynamic conversation , added access token to access mode c:
app.py
CHANGED
|
@@ -1,11 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import random
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
responses = ["Yes","No"] #added here
|
| 6 |
-
return random.choice(responses) #added here
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
chatbot.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
#import random
|
| 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 |
+
messages.append({"role": "user", "content":message})
|
| 14 |
+
|
| 15 |
+
response = client.chat_completion(messages, max_token=100)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
#responses = ["Yes","No"] #added here
|
| 19 |
+
return response['choices'][0]['message']['content'].strip() #added here
|
| 20 |
+
|
| 21 |
+
chatbot = gr.ChatInterface(respond, type="messages", title="Friendly chatbot", ) #chatbot UI - conversion history and user input
|
| 22 |
|
| 23 |
chatbot.launch()
|