Instructions to use colt12/maxcushion with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use colt12/maxcushion with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("colt12/maxcushion", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Download handler.py from colt12/maxcushion: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/colt12/maxcushion/resolve/main/handler.py
- Command line
-
hf download hf://colt12/maxcushion/handler.py
-
curl -L -o handler.py https://huggingface.co/colt12/maxcushion/resolve/main/handler.py
1.77 kB
| import torch | |
| from diffusers import StableDiffusionXLPipeline, DDIMScheduler | |
| import base64 | |
| from io import BytesIO | |
| import os | |
| class InferenceHandler: | |
| def __init__(self): | |
| # Determine the device to run on | |
| self.device = "cuda" if torch.cuda.is_available() else "cpu" | |
| # Get the directory where this script is located | |
| model_dir = os.path.dirname(os.path.abspath(__file__)) | |
| # Print the model directory for debugging purposes | |
| print("Loading model from directory:", model_dir) | |
| # Load the pipeline with authentication | |
| self.pipe = StableDiffusionXLPipeline.from_pretrained( | |
| model_dir, | |
| torch_dtype=torch.float16, | |
| use_safetensors=True, | |
| use_auth_token=os.getenv("HUGGINGFACE_TOKEN") | |
| ).to(self.device) | |
| # Set the scheduler programmatically | |
| self.pipe.scheduler = DDIMScheduler.from_config(self.pipe.scheduler.config) | |
| def __call__(self, inputs): | |
| # Extract the prompt from inputs | |
| prompt = inputs.get("prompt", "") | |
| if not prompt: | |
| raise ValueError("A prompt must be provided") | |
| negative_prompt = inputs.get("negative_prompt", "") | |
| # Generate the image using the pipeline | |
| image = self.pipe( | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| num_inference_steps=30, | |
| guidance_scale=7.5 | |
| ).images[0] | |
| # Convert the image to base64 encoding | |
| buffered = BytesIO() | |
| image.save(buffered, format="PNG") | |
| image_base64 = base64.b64encode(buffered.getvalue()).decode("utf-8") | |
| # Return the base64 image | |
| return {"image_base64": image_base64} | |
| # Instantiate the handler | |
| handler = InferenceHandler() |