Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import random | |
| from 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 = "" | |
| for message in client.chat_completion( | |
| messages, | |
| max_tokens=500, | |
| temperature=0.2, | |
| top_p=0.9, | |
| stream=True | |
| ): | |
| token = message.choices[0].delta.content | |
| response += token | |
| yield response | |
| return response['choices'][0]['message']['content'].strip() | |
| def yes_no(message, history): | |
| response = ['Yes', 'No', '100% yes', 'I think not', 'Possibly', 'Never'] | |
| return random.choice(response) | |
| def echo(message, history): | |
| return message | |
| print("Hello, world!") | |
| chatbot = gr.ChatInterface(yes_no, type="messages", title="Magic Eight Ball", | |
| description="This magic eight ball answers your questions!", | |
| theme=gr.themes.Soft()) | |
| chatbot.launch() |