chatbot1 / app.py
h1ba's picture
changed the description of chatbot
6d13a02 verified
raw
history blame contribute delete
913 Bytes
import gradio as gr
#import random
from huggingface_hub import InferenceClient
client = InferenceClient("microsoft/phi-4")
#def echo(message,history):
# numberval = random.randint(0,1)
# if numberval == 0:
# message = "yes"
#else:
# message = "no"
#return message
def respond(message, history):
messages = [{"role": "system", "content": "You are a polite chatbot helps users understand technical terms in technology."}]
if history:
messages.extend(history)
messages.append({"role": "user", "content": message})
#responses = ["yes", "no"]
response = client.chat_completion(
messages,
max_tokens=100
)
return response['choices'][0]['message']['content'].strip()
#return random.choice(responses)
print("'hello world!'")
chatbot = gr.ChatInterface(respond, type="messages", title="Yes-No Chatbot")
chatbot.launch()