Discord bot
You can make your Gradio app available as a Discord bot to let users in your Discord server interact with it directly.How does it work?
The Discord bot will listen to messages mentioning it in channels. When it receives a message (which can include text as well as files), it will send it to your Gradio app via Gradio’s built-in API. Your bot will reply with the response it receives from the API. Because Gradio’s API is very flexible, you can create Discord bots that support text, images, audio, streaming, chat history, and a wide variety of other features very easily.
Prerequisites
Install the latest version ofgradio and the discord.py libraries:
Create a Discord application
Create new application
First, go to the Discord apps dashboard. Look for the “New Application” button and click it. Give your application a name, and then click “Create”.

Configure bot settings
On the resulting screen, you will see basic information about your application. Under the Settings section, click on the “Bot” option. You can update your bot’s username if you would like.Then click on the “Reset Token” button. A new token will be generated. Copy it as we will need it for the next step.Scroll down to the section that says “Privileged Gateway Intents”. Your bot will need certain permissions to work correctly. In this tutorial, we will only be using the “Message Content Intent” so click the toggle to enable this intent. Save the changes.

Write a Discord bot
Let’s start by writing a very simple Discord bot, just to make sure that everything is working. Write the following Python code in a file calledbot.py, pasting the discord bot token from the previous step:
python bot.py, which should run and print a message like:
bot.py file:
Add the bot to your Discord server
Generate OAuth2 URL
Now we are ready to install the bot on our server. Go back to the Discord apps dashboard. Under the Settings section, click on the “OAuth2” option. Scroll down to the “OAuth2 URL Generator” box and select the “bot” checkbox:

Set permissions
Then in “Bot Permissions” box that pops up underneath, enable the following permissions:

That’s it!
Now you can mention your bot from any channel in your Discord server, optionally attach an image, and it will respond with generated Gradio app code! The bot will:- Listen for mentions
- Process any attached images
- Send the text and images to your Gradio app
- Stream the responses back to the Discord channel
Slack bot
You can make your Gradio app available as a Slack bot to let users in your Slack workspace interact with it directly.How does it work?
The Slack bot will listen to messages mentioning it in channels. When it receives a message (which can include text as well as files), it will send it to your Gradio app via Gradio’s built-in API. Your bot will reply with the response it receives from the API. Because Gradio’s API is very flexible, you can create Slack bots that support text, images, audio, streaming, chat history, and a wide variety of other features very easily.
Prerequisites
Install the latest version ofgradio and the slack-bolt library:
Create a Slack app
Create new app
- Go to api.slack.com/apps and click “Create New App”
- Choose “From scratch” and give your app a name
- Select the workspace where you want to develop your app
Configure permissions
- Under “OAuth & Permissions”, scroll to “Scopes” and add these Bot Token Scopes:
app_mentions:readchat:writefiles:readfiles:write
Install app
- In the same “OAuth & Permissions” page, scroll back up and click the button to install the app to your workspace
- Note the “Bot User OAuth Token” (starts with
xoxb-) that appears as we’ll need it later
Enable Socket Mode
- Click on “Socket Mode” in the menu bar. When the page loads, click the toggle to “Enable Socket Mode”
- Give your token a name, such as
socket-tokenand copy the token that is generated (starts withxapp-) as we’ll need it later
Write a Slack bot
Let’s start by writing a very simple Slack bot, just to make sure that everything is working. Write the following Python code in a file calledbot.py, pasting the two tokens from the previous section:
bot.py file:
Add the bot to your Slack workspace
Now, create a new channel or navigate to an existing channel in your Slack workspace where you want to use the bot. Click the ”+” button next to “Channels” in your Slack sidebar and follow the prompts to create a new channel. Finally, invite your bot to the channel:- In your new channel, type
/invite @YourBotName - Select your bot from the dropdown
- Click “Invite to Channel”
That’s it!
Now you can mention your bot in any channel it’s in, optionally attach an image, and it will respond with generated Gradio app code! The bot will:- Listen for mentions
- Process any attached images
- Send the text and images to your Gradio app
- Stream the responses back to the Slack channel
Website widget
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.Create and style the chat widget
First, add this HTML and CSS to your website: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:
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