Instructions to use socialtrait/flux-3-image-klein-infendpoint with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use socialtrait/flux-3-image-klein-infendpoint with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("socialtrait/flux-3-image-klein-infendpoint", 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
File size: 1,300 Bytes
4b33f36 52a6059 4b33f36 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | """Authenticated HTTP wrapper; Modal queues requests to one resident GPU worker."""
import hmac
import os
from fastapi import Depends, FastAPI, Header, HTTPException
from flux3_engine import GenerationRequest, LegacyRequest
def create_app(engine, startup_error=None):
token = os.environ.get('FLUX_API_TOKEN')
if not token:
raise RuntimeError('FLUX_API_TOKEN must be set for the cloud API')
def authorize(authorization: str | None = Header(default=None)):
if not hmac.compare_digest((authorization or '').encode(), f'Bearer {token}'.encode()):
raise HTTPException(401, 'Invalid bearer token')
app = FastAPI(title='FLUX.3 Klein', dependencies=[Depends(authorize)],
docs_url=None, redoc_url=None, openapi_url=None)
def ready():
if startup_error or not engine or engine.pipe is None:
raise HTTPException(503, startup_error or 'Model not ready')
@app.get('/health')
def health():
ready()
return engine.health()
@app.post('/generate')
def generate(request: GenerationRequest):
ready()
return engine.generate(request)
@app.post('/sdxl')
def legacy(request: LegacyRequest):
ready()
return engine.legacy(request.model_dump())
return app
|