A Text-To-Image Generator using huggingface stable diffusion model to generate images. The app using Tigris as storage to save or load image. The app can be deployed on fly to run the model on fly GPUs.
- 💻 Image hosting: Tigris
- 🦙 Inference: Huggingface,
- 🔌 GPU: Fly
- 🖌️ UI: Gradio
- 🚀 Quickstart
- 💻 [Next Steps](#Next steps)
git clone [email protected]:[YOUR_GITHUB_ACCOUNT_NAME]/tigris-text-to-image.git
- Create an .env file
cd tigris-text-to-image
cp .env.example .env
- Set up Tigris
- Make sure you have a fly.io account and have fly CLI installed on your computer
cd tigris-text-to-image
- Pick a name for your version of your app. App names on fly are global, so it has to be unique. For example
my-tigris-text-to-image-app
- Create the app on fly with
fly app create <your app name>
so for examplefly app create my-tigris-text-to-image-app
- Create the storage with
fly storage create
- You should get a list of credentials like below:
- If you get a list of keys without values, destroy the bucket with
fly storage destroy
and try again. - Copy paste these values to your .env
- Set Tigris bucket cors policy and bucket access policy
fly storage update YOUR_BUCKET_NAME --public
- Make sure you have aws CLI installed and run
aws configure
. Enter theAWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
printed above. Note that these are not actual Amazon Web Services credentials, but Tigris credentials. If you have the aws CLI already configured for Amazon, it will overwrite those values. - Run the following command to update CORS policy on the bucket
aws s3api put-bucket-cors --bucket BUCKET_NAME --cors-configuration file://cors.json --endpoint-url https://fly.storage.tigris.dev/
Running the python app and it will run the gradio server on port 8888.
Once this is running, you can generate an image using the text and then it allows saving the image to Tigris. The bucket name is configured in your .env file. You can also optionally store metadata about this image which Tigris will store along the image. Try to save few images and then load one of the existing image stored.
For local development or to run the server locally, change the following (both are needed mainly to run model locally):
- Install torch package without cuda i.e. remove the suffix "+cu118" from torch package in
requirements.txt
- Update the 'ARCH' in .env file to either 'mps' if you have M1/M2 chip or 'cpu'
fly storage dashboard BUCKET_NAME
(Note: Make sure the torch package in requirements.txt
is with suffix +cu118
and ARCH in .env is cuda
)
By now you should have a functional app, let's deploy it to fly.io cloud account that you setup in Step 1.
- First, lets see what secrets are already available in our app using
fly secrets list
:
$ ➔ fly secrets list
NAME DIGEST CREATED AT
AWS_ACCESS_KEY_ID xxxxxxx Feb 23 2024 20:33
AWS_ENDPOINT_URL_S3 xxxxxxx Feb 23 2024 20:33
AWS_REGION xxxxxxx Feb 23 2024 20:33
AWS_SECRET_ACCESS_KEY xxxxxxx Feb 23 2024 20:33
BUCKET_NAME xxxxxxx Feb 23 2024 20:33
-
We need to match the secrets as in
.env.example
file. -
Now, all other environment vars:
-
Once environment is all set, we can make the app fly:
$ ➔ fly launch
$ ➔ fly deploy
🎉 All done. You should be able to use app on the URL provided by Fly.
In a few steps, we learnt how to bootstrap a app using Tigris and deploy it on Fly. Feel free to add more functionalities or customize App for your use-case.