first-chat-bot / app.py
Ire-O's picture
Correct spelling error
2c5331e verified
import gradio as gr # imports the gradio library
import random
from huggingface_hub import InferenceClient
client = InferenceClient("microsoft/phi-4")
# returns the message back to the user
def echo(message, history):
return message
# returns yes or no back to the user
def yes_or_no(message, history):
responses = ["Yes","No"]
return random.choice(responses) #randomly returns one
# returns a message back to the user
def response(message, history):
messages = [{"role":"system","content":"You are a friendly chatbot :)"}]
if history:
messages.extend(history)
messages.append({"role":"user", "content":message})
responses = client.chat_completion(
messages,
max_tokens = 100 #chunks of material
)
return responses['choices'][0]['message']['content'].strip() #returns response from library
#print("Hello world!") #prints in the logs
chatbot = gr.ChatInterface(response, type="messages", title="chatbot bestie") # chatbout ui - history & input
chatbot.launch() # lauches chatbot