Upload 3 files
Browse files- .gitattributes +1 -0
- check.py +8 -0
- handler.py +25 -0
- image.png +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
image.png filter=lfs diff=lfs merge=lfs -text
|
check.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from handler import EndpointHandler
|
2 |
+
|
3 |
+
my_handler = EndpointHandler()
|
4 |
+
payload = {"inputs": {"prompt": "a dog waiting for its companion to come."}}
|
5 |
+
|
6 |
+
# test the handler
|
7 |
+
image = my_handler(payload)
|
8 |
+
image.save("image.png")
|
handler.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import DiffusionPipeline
|
2 |
+
from typing import Any, Dict, List
|
3 |
+
import torch
|
4 |
+
|
5 |
+
class EndpointHandler:
|
6 |
+
def __init__(self):
|
7 |
+
self.pipeline = DiffusionPipeline.from_pretrained(
|
8 |
+
"stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.bfloat16
|
9 |
+
).to("cuda")
|
10 |
+
|
11 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
12 |
+
inputs = data.pop("inputs")
|
13 |
+
prompt = inputs.pop("prompt", "dog")
|
14 |
+
guidance_scale = inputs.pop("guidance_scale", 4.5)
|
15 |
+
num_inference_steps = inputs.pop("num_inference_steps", 28)
|
16 |
+
seed = inputs.pop("seed", 0)
|
17 |
+
|
18 |
+
prediction = self.pipeline(
|
19 |
+
prompt,
|
20 |
+
negative_prompt="bad quality, worse quality, deformed",
|
21 |
+
guidance_scale=guidance_scale,
|
22 |
+
num_inference_steps=num_inference_steps,
|
23 |
+
generator=torch.manual_seed(seed)
|
24 |
+
).images[0]
|
25 |
+
return prediction
|
image.png
ADDED
Git LFS Details
|