Skip to content

A slack bot for generating images with OpenAI's text to image API.

License

Notifications You must be signed in to change notification settings

JamesBLewis/slack-to-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A slack bot for generating images with DALL-E

This repository contains a Slack bot that generates and displays images based on prompts using OpenAI's API. The bot listens for commands in Slack channels and responds with images generated by OpenAI.

Prerequisites

To run this Slack bot, you need to have the following prerequisites:

  • Python (version 3.7 or higher)
  • Slack workspace with the ability to add a new app
  • OpenAI org and API keys
  • Slack app token and bot token

Installation

  1. Clone this repository to your local machine:

    git clone https://github.com/JamesBLewis/slack-to-image.git
    
  2. Change to the cloned repository's directory:

    cd slack-to-image/app
    
  3. Install the required Python dependencies:

    pip install -r requirements.txt
    

Configuration

OpenAI

All you need from here is an ORG_KEY and API key.

  1. Fetch your org key (OPENAI_ORG) from the account settings page.
  2. Create a new API key (OPENAI_KEY) on the API key Page.

Slack

To set up the Slack app and slash command, follow these steps:

  1. Go to the Slack API website and sign in to your workspace.
  2. Create a new Slack app by clicking on "Create an App" and provide a name and select the workspace where you want to install the app.
  3. Enable Socket Mode by navigating to the "Socket Mode" section in your app's settings and turning it on.
  4. In the "Slash Commands" section, click on "Create New Command". Set the command as /imagine.
  5. Generate an app-level token by navigating to the "Basic Information" page of your app. Under "App-Level Tokens", click on "Generate Token and Scopes". Make sure to include the scope "connections:write".
  6. Copy the "App Level Tokens" (SLACK_XAPP) from the above step and the "Bot User OAuth Tokens" (SLACK_XOXB) from the "OAuth & Permissions" page.

Local

Before running the bot, you need to configure the necessary environment variables. Open the .env file in the repository directory and update the values accordingly:

SLACK_XAPP=<slack-app-token>
SLACK_XOXB=<slack-bot-token>
OPENAI_ORG=<openai-organization>
OPENAI_KEY=<openai-api-key>

Replace <slack-app-token>, <slack-bot-token>, <openai-organization>, and <openai-api-key> with your actual tokens and keys.

Usage

To start the Slack bot, run the following command:

python ./app/main.py

The bot will establish a connection to your Slack workspace and start listening for commands.

Command

To generate and display images, use the /imagine command in a Slack channel where the bot is installed. The command accepts a prompt as an argument.

/imagine <prompt>

Replace <prompt> with the text that describes the desired image. The bot will generate images based on the provided prompt and display them in the channel. Optionally you may prefix your can prefix your prompt with x4 (where 4 is some int between 1 and 10). This will result in the desired number of images being generated.

Contributing

If you want to contribute to this project, you can fork the repository, make changes, and submit a pull request. Please ensure that your code follows the existing style and includes appropriate documentation and tests.

License

This project is licensed under the MIT License.

Thanks

Very heavily inspired by slack-diffusion by Dylan Butler.

About

A slack bot for generating images with OpenAI's text to image API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published