import gradio as gr from huggingface_hub import InferenceClient def chat_with_bot(user_input, history, hf_token): client = InferenceClient(repo_id="facebook/blenderbot-400M-distill", token=hf_token) response = client(inputs=user_input, parameters={"max_new_tokens": 100, "do_sample": True}) bot_reply = response['generated_text'].strip() history.append((user_input, bot_reply)) return bot_reply, history with gr.Blocks() as demo: gr.Markdown("## Chat with BlenderBot (supports complex topics)") hf_token_input = gr.Textbox(label="Hugging Face API Token", type="password") chat_box = gr.Chatbot() user_input = gr.Textbox(label="Your message") send_button = gr.Button("Send") chat_history = [] def respond(user_message, chat_history, token): reply, new_history = chat_with_bot(user_message, chat_history, token) chat_history.append((user_message, reply)) return chat_history, new_history send_button.click( respond, inputs=[user_input, chat_box, hf_token_input], outputs=[chat_box, "state"] ) demo.launch(share=True) import gradio as gr from huggingface_hub import InferenceApi def chat_with_bot( user_input, history, hf_token ): client = InferenceApi(repo_id="facebook/blenderbot-400M-distill", token=hf_token) response = client(inputs=user_input, parameters={"max_new_tokens": 100, "do_sample": True}) bot_reply = response['generated_text'].strip() # Update chat history history.append((user_input, bot_reply)) return bot_reply, history with gr.Blocks() as demo: gr.Markdown("## Chat with BlenderBot (supports complex topics)") hf_token_input = gr.Textbox(label="Hugging Face API Token", type="password") chat_box = gr.Chatbot() user_input = gr.Textbox(label="Your message") send_button = gr.Button("Send") chat_history = [] def respond(user_message, chat_history, token): reply, new_history = chat_with_bot(user_message, chat_history, token) chat_history.append((user_message, reply)) return chat_history, new_history send_button.click( respond, inputs=[user_input, chat_box, hf_token_input], outputs=[chat_box, "state"] ) demo.launch(share=True)