Update app.py
Browse filesturned random into general chatbot
app.py
CHANGED
|
@@ -1,5 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
#def echo(message,history):
|
| 5 |
# numberval = random.randint(0,1)
|
|
@@ -9,10 +15,24 @@ import random
|
|
| 9 |
# message = "no"
|
| 10 |
#return message
|
| 11 |
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
print("'hello world!'")
|
| 17 |
|
| 18 |
chatbot = gr.ChatInterface(respond_yes_no_randomly, type="messages", title="Yes-No Chatbot")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
#import random
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
|
| 5 |
+
client = InferenceClient("microsoft/phi-4")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
|
| 10 |
#def echo(message,history):
|
| 11 |
# numberval = random.randint(0,1)
|
|
|
|
| 15 |
# message = "no"
|
| 16 |
#return message
|
| 17 |
|
| 18 |
+
def respond(message, history):
|
| 19 |
+
|
| 20 |
+
messages = [{"role": "system", "content": "You are a friendly chatbot."]
|
| 21 |
+
|
| 22 |
+
if history:
|
| 23 |
+
messages.extend(history)
|
| 24 |
+
|
| 25 |
+
messages.append({"role": "user", "content": message})
|
| 26 |
+
#responses = ["yes", "no"]
|
| 27 |
+
response = client.chat_completion(
|
| 28 |
+
messages,
|
| 29 |
+
max_tokens=100
|
| 30 |
+
)
|
| 31 |
+
return response['choices'][0]['message']['content'].strip()
|
| 32 |
+
#return random.choice(responses)
|
| 33 |
+
|
| 34 |
|
| 35 |
+
|
| 36 |
print("'hello world!'")
|
| 37 |
|
| 38 |
chatbot = gr.ChatInterface(respond_yes_no_randomly, type="messages", title="Yes-No Chatbot")
|