Tags: CHAT, DEPLOY, WEB
🚀 Creating a Website Chat Widget with Gradio 🚀
Tags: CHAT, DEPLOY, WEB
You can make your Gradio Chatbot available as an embedded chat widget on your website, similar to popular customer service widgets like Intercom. This is particularly useful for:
- Adding AI assistance to your documentation pages
- Providing interactive help on your portfolio or product website
- Creating a custom chatbot interface for your Gradio app
How does it work?
The chat widget appears as a small button in the corner of your website. When clicked, it opens a chat interface that communicates with your Gradio app via the JavaScript Client API. Users can ask questions and receive responses directly within the widget.
Prerequisites
- A running Gradio app (local or on Hugging Face Spaces). In this example, we'll use the Gradio Playground Space, which helps generate code for Gradio apps based on natural language descriptions.
1. Create and Style the Chat Widget
First, add this HTML and CSS to your website:
<div id="chat-widget" class="chat-widget">
<button id="chat-toggle" class="chat-toggle">💬</button>
<div id="chat-container" class="chat-container hidden">
<div id="chat-header">
<h3>Gradio Assistant</h3>
<button id="close-chat">×</button>
</div>
<div id="chat-messages"></div>
<div id="chat-input-area">
<input type="text" id="chat-input" placeholder="Ask a question...">
<button id="send-message">Send</button>
</div>
</div>
</div>
2. Add the JavaScript
Then, add the following JavaScript code (which uses the Gradio JavaScript Client to connect to the Space) to your website by including this in the <head> section of your website:
3. That's it!
Your website now has a chat widget that connects to your Gradio app! Users can click the chat button to open the widget and start interacting with your app.
Customization
You can customize the appearance of the widget by modifying the CSS. Some ideas:
- Change the colors to match your website's theme
- Adjust the size and position of the widget
- Add animations for opening/closing
- Modify the message styling
If you build a website widget from a Gradio app, feel free to share it on X and tag the Gradio account, and we are happy to help you amplify!
Source and license
Source: Gradio documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.