Spaces:
Sleeping
Sleeping
File size: 1,006 Bytes
46c5fdb a7bb3cd c83c38c a7bb3cd b91b11e a7bb3cd 46c5fdb a7bb3cd 46c5fdb 381e1db e330931 a7bb3cd 3800091 e330931 d1ecb03 46c5fdb |
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 34 35 36 |
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() |