Spaces:
Sleeping
Sleeping
| 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() |