Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") | |
| user_profile = { | |
| "name": "" | |
| } | |
| def set_user_profile(name): | |
| user_profile['name'] = name | |
| return name | |
| def respond(message, history): | |
| messages = [{"role": "system", "content": f"You are a friendly chatbot. You are talking to {user_profile['name']}. Use their name in your initial response."}] | |
| if history: | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": message}) | |
| response = client.chat_completion(messages) | |
| print(messages) | |
| return response['choices'][0]['message']['content'].strip() | |
| with gr.Blocks() as chatbot: | |
| with gr.Row(): | |
| with gr.Column(): | |
| name = gr.Textbox(label="Name") | |
| submit_btn = gr.Button("Submit") | |
| submit_btn.click(set_user_profile, inputs=name, outputs=[]) | |
| with gr.Column(): | |
| gr.ChatInterface(respond, type="messages") | |
| chatbot.launch() |