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 app.py from colt12/maxcushion: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/colt12/maxcushion/resolve/main/app.py
- Command line
-
hf download hf://colt12/maxcushion/app.py
-
curl -L -o app.py https://huggingface.co/colt12/maxcushion/resolve/main/app.py
1.33 kB
| from typing import Dict, List | |
| from fastapi import FastAPI, HTTPException | |
| from pydantic import BaseModel | |
| from diffusers import StableDiffusionXLPipeline | |
| import torch | |
| import base64 | |
| from io import BytesIO | |
| app = FastAPI() | |
| # Load the model | |
| model_name = "colt12/maxcushion" | |
| pipe = StableDiffusionXLPipeline.from_pretrained(model_name, torch_dtype=torch.float16, use_safetensors=True, variant="fp16") | |
| pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") | |
| class Item(BaseModel): | |
| prompt: str | |
| negative_prompt: str = "" | |
| num_inference_steps: int = 30 | |
| guidance_scale: float = 7.5 | |
| async def generate(item: Item) -> Dict[str, str]: | |
| try: | |
| # Generate the image | |
| image = pipe( | |
| prompt=item.prompt, | |
| negative_prompt=item.negative_prompt, | |
| num_inference_steps=item.num_inference_steps, | |
| guidance_scale=item.guidance_scale | |
| ).images[0] | |
| # Convert to base64 | |
| buffered = BytesIO() | |
| image.save(buffered, format="PNG") | |
| image_base64 = base64.b64encode(buffered.getvalue()).decode("utf-8") | |
| return {"image": image_base64} | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def root(): | |
| return {"message": "SDXL Image Generation API"} |