Coder Social home page Coder Social logo

dalle_slackbot's Introduction

Setup & Installation

ngrok http 3000

This exposes your local flask server using a randomly assigned URL that you get from the command. This will be of the form https://.ngrok.io. Note this URL will change everytime you restart ngrok.

  • Create a new Slack App: https://api.slack.com/apps
    • Click "Create New App", choose "From scratch" option
    • Provide an App Name, Select a workspace
    • Add Features & Functionality
      • Slash Commands:
        • Command: /galle
        • Request URL: provide the ngrok URL you got above
        • Short Description: Generates an image from a text prompt using Dall-E
        • Usage Hint: ""
      • OAuth & Permissions
        • The Bot User OAuth Token you see here is the slack token you will use in your code
        • Scopes: Enable the following bot token scopes: chat:write, chat:write_customize, chat:write.public, commands, incoming-webhook
      • Activate Incoming Webhooks
        • The webhook URL you see here is what is provided as the response URL in the code
    • Install your app:
      • Install to Workspace: specify channels that the bot can post to
    • Manage Distribution: To install app in other workspaces

Replicate API

Although you can run the DALL-E mini and similar models locally, they take a significant amount of compute and a GPU to run in a reasonable amount of time. For this implementation, I opted to get the images using the Replicate API. This requires a "Hobby" subscription ($10/month). The API token is provided in the code.

There are several models available via Replicate and the code allows you to switch using the following dict:

model_dict = {"borisdayma": "borisdayma/dalle-mini",
              "kuprel": "kuprel/min-dalle",
              "mehdidc": "mehdidc/feed_forward_vqgan_clip"}

The first two take ~ 25 sec, the third one is significantly faster at ~ 3 sec.

Run flask server

  • Create a conda environment:
conda create -n "dalle" python=3.8
pip install flask replicate 
  • Run flask server to serve generated images to slack workspace
python dalle_slackbot.py

Run on Google Cloud

  • Create a basic f1-micro (~$5/month) instance
  • Installation
# Get ngrok & other tools
curl https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok-stable-linux-amd64.zip
sudo apt-get install unzip tmux git
unzip ngrok-stable-linux-amd64.zip
  • Run ngrok in a tmux session
tmux
./ngrok authtoken <token>
  • Run flask server in a separate tmux session
tmux
git clone https://github.com/sanzgiri/dalle_slackbot.git
pip3 install flask replicate packaging
cd dalle_slackbot
python3 dalle_slackbot.py

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.