first_chatbot / app.py
jillsundie's picture
l11 fix
7385782 verified
import gradio as gr
import random
from huggingface_hub import InferenceClient
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta",token=userdata.get('HF_TOKEN'))
def respond(message, history):
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
if history:
messages.extend(history)
messages.append({"role": "user", "content": message})
#make the chat completion API call, sending the messages and other parameters to the model
response = client.chat_completion(
messages,
max_tokens=100,
temperature=0.2
)
#extract and return the chatbot's response
return response['choices'][0]['message']['content'].strip()
#def yorn(message,history):
#responses=["yes","no"]
#return random.choice(responses)
#def echo(message,history):
#print("hello world")
#return message
#def eightball(message,history):
#responses=["Your luck has run out","It's your lucky day","You are so insightful"]
#return random.choice(responses)
chatbot=gr.ChatInterface(respond, type='messages')
chatbot.launch()