Spaces:
Runtime error
Runtime error
practiced for lesson 11 generative AI
Browse files12345678910111213141516171819202122232425262710282930import gradio as grimport randomfrom huggingface_hub import InferenceClient
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
def respond(message, history): messages = [{"role": "system", "content": "You are a friendly chatbot."}] if history: messages.extend(history)
messages.append({"role":"user", "content": message})
response = client.chat_completion(messages, max_tokens=100)
print(response['choices'][0]['message']['content'].strip()) return response['choices'][0]['message']['content'].strip() def random_message(message, history): choices = ["yes.", "no.", "it is certain","without a doubt","outlook good","ask again later", "better not tell you now","very doubtful","don't count on it","my sources say no","outlook not so good","very doubtful","reply hazy, try again", "cannot predict now"] chat_answer = random.choice(choices) return chat_answer
print("Hello, World!")chatbot = gr.ChatInterface(random_message, type = "messages", theme = 'gstaff/xkcd', editable = True, title = "8ball" )chatbot = gr.ChatInterface(respond, type = "messages")
chatbot.launch()app.py+19-1