Views
No views yet
Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input. For more information about how Stable Diffusion functions, please have a look at 🤗's Stable Diffusion with 🧨Diffusers blog.
handler task for text-to-image for 🤗 Inference Endpoints. The code for the customized pipeline is in the pipeline.py.handler.py1{
2 "inputs": "A prompt used for image generation"
3}requests.1import json
2from typing import List
3import requests as r
4import base64
5from PIL import Image
6from io import BytesIO
7
8ENDPOINT_URL = ""
9HF_TOKEN = ""
10
11# helper decoder
12def decode_base64_image(image_string):
13 base64_image = base64.b64decode(image_string)
14 buffer = BytesIO(base64_image)
15 return Image.open(buffer)
16
17
18def predict(prompt:str=None):
19 payload = {"inputs": code_snippet,"parameters": parameters}
20 response = r.post(
21 ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json={"inputs": prompt}
22 )
23 resp = response.json()
24 return decode_base64_image(resp["image"])
25
26prediction = predict(
27 prompt="the first animal on the mars"
28)