Upload folder using huggingface_hub
Browse filesFiles changed (5)
- README.md+50
- handdrawn.pngAdded
- handler.py+1-1
- output.pngAdded
- test_endpoint.pyAdded+44
7 unmodified lines891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859607 unmodified lines---
# Inference Endpoint for [Seg2Sat](https://huggingface.co/rgres/Seg2Sat-sd-controlnet) using [runwayml/stable-diffusion-v1-5](https://huggingface.co/stabilityai/stable-diffusion-2-1-base)
You can call the inference endpoint like this :
```import base64import requests
API_URL = "https://zqz606ggn85ysase.us-east-1.aws.endpoints.huggingface.cloud"
def encode_image(image_path): with open(image_path, "rb") as i: b64 = base64.b64encode(i.read()) return b64.decode("utf-8")
prompt = "aerial view of jardin princier, Toulouse. Flowers, flowers, garden"image = encode_image("handdrawn.png")
headers = { "Accept": "image/png", "Content-Type": "application/json"}
# test the handlerdef query(payload): response = requests.post(API_URL, headers=headers, json=payload) return response.content
payload = { "inputs": prompt, "prompt": prompt, "image": image, "steps": 20, "seed": 999}
import jsonwith open('payload.json', 'w') as f: json.dump(payload, f)
image_bytes = query(payload)
# You can access the image with PIL.Image for exampleimport iofrom PIL import Imageimage = Image.open(io.BytesIO(image_bytes))
image.save("output.png")
```39 unmodified lines404142434344454639 unmodified lines # decode image image = self.decode_base64_image(image)
self.generator = torch.Generator(device="cpu").manual_seed(3) self.generator = torch.Generator(device="cpu").manual_seed(seed) # run inference pipeline image_out = self.pipe(1234567891011121314151617181920212223242526272829303132333435363738394041424344import base64import requests
API_URL = "https://zqz606ggn85ysase.us-east-1.aws.endpoints.huggingface.cloud"
def encode_image(image_path): with open(image_path, "rb") as i: b64 = base64.b64encode(i.read()) return b64.decode("utf-8")
prompt = "aerial view of jardin princier, Toulouse. Flowers, flowers, garden"image = encode_image("handdrawn.png")
headers = { "Accept": "image/png", "Content-Type": "application/json"}
# test the handlerdef query(payload): response = requests.post(API_URL, headers=headers, json=payload) return response.content
payload = { "inputs": prompt, "prompt": prompt, "image": image, "steps": 20, "seed": 999}
import jsonwith open('payload.json', 'w') as f: json.dump(payload, f)
image_bytes = query(payload)
# You can access the image with PIL.Image for exampleimport iofrom PIL import Imageimage = Image.open(io.BytesIO(image_bytes))
image.save("output.png")README.md+50
handdrawn.pngAdded

handler.py+1-1
output.pngAdded

test_endpoint.pyAdded+44