forked from inferless/animagine-xl-3.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
50 lines (42 loc) · 1.36 KB
/
app.py
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
42
43
44
45
46
47
48
49
50
import torch
from diffusers import (
StableDiffusionXLPipeline,
EulerAncestralDiscreteScheduler,
AutoencoderKL
)
from io import BytesIO
import base64
import os
class InferlessPythonModel:
def initialize(self):
# Load VAE component
self.vae = AutoencoderKL.from_pretrained(
"madebyollin/sdxl-vae-fp16-fix",
torch_dtype=torch.float16
)
# Configure the pipeline
self.pipe = StableDiffusionXLPipeline.from_pretrained(
"cagliostrolab/animagine-xl-3.0",
vae=self.vae,
torch_dtype=torch.float16,
use_safetensors=True,
)
self.pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe.scheduler.config)
self.pipe.to('cuda')
def infer(self, inputs):
prompt = inputs["prompt"]
negative_prompt = inputs["negative_prompt"]
image = self.pipe(
prompt,
negative_prompt=negative_prompt,
width=832,
height=1216,
guidance_scale=7,
num_inference_steps=28
).images[0]
buff = BytesIO()
image.save(buff, format="JPEG")
img_str = base64.b64encode(buff.getvalue()).decode()
return { "generated_image_base64" : img_str }
def finalize(self):
self.pipe = None