Spaces:
Sleeping
Sleeping
File size: 1,348 Bytes
50ae49f b9e324f 0bf84d3 50ae49f 216b82d 67d4bf6 b9e324f 8a85b99 a29a491 216b82d 50ae49f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import gradio as gr
import random
from huggingface_hub import InferenceClient
#import lines fo at the top! Any libraries I need to import go here
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
def respond(message, history):
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
#system message
if history:
messages.extend(history)
messages.append({"role": "user", "content": message})
#user message
response = client.chat_completion(messages, max_tokens = 100)
#max_tokens caps the number od letters in the return message
return response['choices'][0]['message']["content"].strip()
def magic_8_ball(message, history):
return random.choice(['Yes', "No","Try again", "Definitely", "Most likely not", "Without a doubt"])
#def yes_or_no(message, history):
#return random.choice(['Yes', "No"])
#def echo(message, history):
#return message
#a function that the user's message is repeated back to you
print("Hello World")
chatbot = gr.ChatInterface(respond, type="messages", title="Magic 8 Ball", description="I will answer all of your questions about the future! Matt's ex: https://huggingface.co/spaces/mgetz/SanFran/blob/main/app.py")
#defining my chatbot so that the user can interact and see their conversation history and send me messages
chatbot.launch() |