add large file
Browse files- .gitattributes +0 -14
- README.md +0 -50
- handler.py +0 -47
- stable-diffusion-v1-5 +0 -1
- stable-diffusion-v1-5/v1-5-pruned.ckpt +3 -0
.gitattributes
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
stable-diffusion-v1-5/ filter=lfs diff=lfs merge=lfs -text
|
2 |
-
stable-diffusion-v1-5/README.md filter=lfs diff=lfs merge=lfs -text
|
3 |
-
stable-diffusion-v1-5/tokenizer filter=lfs diff=lfs merge=lfs -text
|
4 |
-
stable-diffusion-v1-5/v1-inference.yaml filter=lfs diff=lfs merge=lfs -text
|
5 |
-
stable-diffusion-v1-5/text_encoder filter=lfs diff=lfs merge=lfs -text
|
6 |
-
stable-diffusion-v1-5/unet filter=lfs diff=lfs merge=lfs -text
|
7 |
-
stable-diffusion-v1-5/v1-5-pruned.ckpt filter=lfs diff=lfs merge=lfs -text
|
8 |
-
stable-diffusion-v1-5/v1-5-pruned-emaonly.ckpt filter=lfs diff=lfs merge=lfs -text
|
9 |
-
stable-diffusion-v1-5/feature_extractor filter=lfs diff=lfs merge=lfs -text
|
10 |
-
stable-diffusion-v1-5/model_index.json filter=lfs diff=lfs merge=lfs -text
|
11 |
-
stable-diffusion-v1-5/safety_checker filter=lfs diff=lfs merge=lfs -text
|
12 |
-
stable-diffusion-v1-5/scheduler filter=lfs diff=lfs merge=lfs -text
|
13 |
-
stable-diffusion-v1-5/vae filter=lfs diff=lfs merge=lfs -text
|
14 |
-
stable-diffusion-v1-5/* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
DELETED
@@ -1,50 +0,0 @@
|
|
1 |
-
---
|
2 |
-
license: creativeml-openrail-m
|
3 |
-
tags:
|
4 |
-
- stable-diffusion
|
5 |
-
- stable-diffusion-diffusers
|
6 |
-
- endpoints-template
|
7 |
-
duplicated_from: philschmid/stable-diffusion-v1-4-endpoints
|
8 |
-
---
|
9 |
-
# Fork of [CompVis/stable-diffusion-v1-4](https://huggingface.co/CompVis/stable-diffusion-v1-4)
|
10 |
-
> Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.
|
11 |
-
> For more information about how Stable Diffusion functions, please have a look at [🤗's Stable Diffusion with 🧨Diffusers blog](https://huggingface.co/blog/stable_diffusion).
|
12 |
-
For more information about the model, license and limitations check the original model card at [CompVis/stable-diffusion-v1-4](https://huggingface.co/CompVis/stable-diffusion-v1-4).
|
13 |
-
### License (CreativeML OpenRAIL-M)
|
14 |
-
The full license can be found here: https://huggingface.co/spaces/CompVis/stable-diffusion-license
|
15 |
-
---
|
16 |
-
This repository implements a custom `handler` task for `text-to-image` for 🤗 Inference Endpoints. The code for the customized pipeline is in the [pipeline.py](https://huggingface.co/philschmid/stable-diffusion-v1-4-endpoints/blob/main/handler.py).
|
17 |
-
There is also a [notebook](https://huggingface.co/philschmid/stable-diffusion-v1-4-endpoints/blob/main/create_handler.ipynb) included, on how to create the `handler.py`
|
18 |
-
### expected Request payload
|
19 |
-
```json
|
20 |
-
{
|
21 |
-
"inputs": "A prompt used for image generation"
|
22 |
-
}
|
23 |
-
```
|
24 |
-
below is an example on how to run a request using Python and `requests`.
|
25 |
-
## Run Request
|
26 |
-
```python
|
27 |
-
import json
|
28 |
-
from typing import List
|
29 |
-
import requests as r
|
30 |
-
import base64
|
31 |
-
from PIL import Image
|
32 |
-
from io import BytesIO
|
33 |
-
ENDPOINT_URL = ""
|
34 |
-
HF_TOKEN = ""
|
35 |
-
# helper decoder
|
36 |
-
def decode_base64_image(image_string):
|
37 |
-
base64_image = base64.b64decode(image_string)
|
38 |
-
buffer = BytesIO(base64_image)
|
39 |
-
return Image.open(buffer)
|
40 |
-
def predict(prompt:str=None):
|
41 |
-
payload = {"inputs": code_snippet,"parameters": parameters}
|
42 |
-
response = r.post(
|
43 |
-
ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json={"inputs": prompt}
|
44 |
-
)
|
45 |
-
resp = response.json()
|
46 |
-
return decode_base64_image(resp["image"])
|
47 |
-
prediction = predict(
|
48 |
-
prompt="the first animal on the mars"
|
49 |
-
)
|
50 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handler.py
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
import base64
|
2 |
-
from io import BytesIO
|
3 |
-
from typing import Dict, List, Any
|
4 |
-
|
5 |
-
import torch
|
6 |
-
from PIL import Image
|
7 |
-
from diffusers import StableDiffusionPipeline
|
8 |
-
|
9 |
-
|
10 |
-
REPO_ID = "runwayml/stable-diffusion-v1-5"
|
11 |
-
|
12 |
-
|
13 |
-
# helper decoder
|
14 |
-
def decode_base64_image(image_string):
|
15 |
-
base64_image = base64.b64decode(image_string)
|
16 |
-
buffer = BytesIO(base64_image)
|
17 |
-
return Image.open(buffer)
|
18 |
-
|
19 |
-
|
20 |
-
class EndpointHandler:
|
21 |
-
def __init__(self, path=""):
|
22 |
-
self.pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16,
|
23 |
-
revision="fp16", use_auth_token="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")
|
24 |
-
self.pipe = self.pipe.to("cuda")
|
25 |
-
|
26 |
-
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
27 |
-
"""
|
28 |
-
Args:
|
29 |
-
data (:obj:):
|
30 |
-
includes the input data and the parameters for the inference.
|
31 |
-
Return:
|
32 |
-
A :obj:`dict`:. base64 encoded image
|
33 |
-
"""
|
34 |
-
prompts = data.pop("inputs", None)
|
35 |
-
encoded_image = data.pop("image", None)
|
36 |
-
init_image = None
|
37 |
-
if encoded_image:
|
38 |
-
init_image = decode_base64_image(encoded_image)
|
39 |
-
init_image.thumbnail((768, 768))
|
40 |
-
image = self.pipe(prompts, init_image=init_image).images[0]
|
41 |
-
|
42 |
-
# encode image as base 64
|
43 |
-
buffered = BytesIO()
|
44 |
-
image.save(buffered, format="png")
|
45 |
-
|
46 |
-
# post process the prediction
|
47 |
-
return {"image": buffered.getvalue()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stable-diffusion-v1-5
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
Subproject commit 63534535d4730d5976c5c647a7f2adaea1102f5b
|
|
|
|
stable-diffusion-v1-5/v1-5-pruned.ckpt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e1441589a6f3c5a53f5f54d0975a18a7feb7cdf0b0dee276dfc3331ae376a053
|
3 |
+
size 7703807346
|