Quoc Bao Bui
commited on
Commit
·
e762c44
1
Parent(s):
a7eb3c4
Update README
Browse files
README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
| 1 |
---
|
| 2 |
-
license: openrail
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: creativeml-openrail-m
|
| 3 |
+
tags:
|
| 4 |
+
- stable-diffusion
|
| 5 |
+
- stable-diffusion-diffusers
|
| 6 |
+
- text-to-image
|
| 7 |
+
- endpoints-template
|
| 8 |
+
inference: false
|
| 9 |
+
duplicated_from: philschmid/stable-diffusion-v1-4-endpoints
|
| 10 |
---
|
| 11 |
+
# Fork of [CompVis/stable-diffusion-v1-4](https://huggingface.co/CompVis/stable-diffusion-v1-4)
|
| 12 |
+
> Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.
|
| 13 |
+
> 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).
|
| 14 |
+
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).
|
| 15 |
+
### License (CreativeML OpenRAIL-M)
|
| 16 |
+
The full license can be found here: https://huggingface.co/spaces/CompVis/stable-diffusion-license
|
| 17 |
+
---
|
| 18 |
+
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).
|
| 19 |
+
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`
|
| 20 |
+
### expected Request payload
|
| 21 |
+
```json
|
| 22 |
+
{
|
| 23 |
+
"inputs": "A prompt used for image generation"
|
| 24 |
+
}
|
| 25 |
+
```
|
| 26 |
+
below is an example on how to run a request using Python and `requests`.
|
| 27 |
+
## Run Request
|
| 28 |
+
```python
|
| 29 |
+
import json
|
| 30 |
+
from typing import List
|
| 31 |
+
import requests as r
|
| 32 |
+
import base64
|
| 33 |
+
from PIL import Image
|
| 34 |
+
from io import BytesIO
|
| 35 |
+
ENDPOINT_URL = ""
|
| 36 |
+
HF_TOKEN = ""
|
| 37 |
+
# helper decoder
|
| 38 |
+
def decode_base64_image(image_string):
|
| 39 |
+
base64_image = base64.b64decode(image_string)
|
| 40 |
+
buffer = BytesIO(base64_image)
|
| 41 |
+
return Image.open(buffer)
|
| 42 |
+
def predict(prompt:str=None):
|
| 43 |
+
payload = {"inputs": code_snippet,"parameters": parameters}
|
| 44 |
+
response = r.post(
|
| 45 |
+
ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json={"inputs": prompt}
|
| 46 |
+
)
|
| 47 |
+
resp = response.json()
|
| 48 |
+
return decode_base64_image(resp["image"])
|
| 49 |
+
prediction = predict(
|
| 50 |
+
prompt="the first animal on the mars"
|
| 51 |
+
)
|
| 52 |
+
```
|