An API server to transform text into images using using the diffusers library on CUDA hardware
576
An API server to transform text into images using using the diffusers library on CUDA hardware.
import requests
import base64
from IPython.display import Image, display
url = 'http://localhost:8000/generate-image'
data = {
'model': 'dataautogpt3/OpenDalleV1.1',
'prompt': 'Aerial view of a futuristic cityscape getting tip-toed on by a giant kitten acting like godzilla',
'negative_prompt': "(worst quality, low quality, simpsons hands)",
'width': 1024,
'height': 1024,
'image_type': 'png',
'num_inference_steps': 40,
'safety': True
}
response = requests.post(url, json=data)
response_data = response.json()
# Check the response and display the image
if response.status_code == 200 and 'image' in response_data:
encoded_image = response_data['image']
mime_type = response_data['mime_type']
# Decode the Base64 string to bytes
image_bytes = base64.b64decode(encoded_image)
# Display the image
display(Image(data=image_bytes, format=mime_type.split('/')[-1], embed=True))
else:
print("Failed to generate image:", response.text)
Build the docker image
$ docker build --no-cache -t gonk-diffusers-api .
Then run the container, be sure nvidia docker runtime is installed.
$ docker run --runtime=nvidia \
--rm -p 8000:8000 \
-v /path/to/huggingface-hub-cache:/path/to/huggingface-hub-cache \
gonk-diffusers-api \
--hf-cache-path /path/to/huggingface-hub-cache \
--hf-local-files-only
Note: The huggingface-hub-cache refers to the directory holding the models--.. folders.
requirements.txt file.git clone https://github.com/jason-weirather/gonk-diffusers-api.git
cd gonk-diffusers-api
pip install -r requirements.txt
Start the server using the CLI:
python -m gonk-diffusers-api.cli
Optional CLI arguments:
-H, --host: Host address (default 0.0.0.0).-p, --port: Port number (default 8000).--require-auth: Enable API key authentication./generate-image: Generates an image from a given text prompt./status: Retrieves the server and CUDA status.To enable API authentication, set the GONK_DIFFUSERS_API_KEY environment variable and start the server with the --require-auth flag.
Access the interactive API documentation by navigating to http://localhost:8000/docs.
This project is licensed under the Apache License 2.0.
Content type
Image
Digest
sha256:3c564d78d…
Size
5.3 GB
Last updated
over 2 years ago
docker pull vacation/gonk-diffusers-api