File size: 1,403 Bytes
16b3d38
 
 
 
 
 
 
 
 
68da561
1273ba8
bda5885
 
1273ba8
bda5885
 
1273ba8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
license: openrail
tags:
- stable-diffusion
- stable-diffusion-diffusers
- controlnet
inference: true
---

# 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)

The code from the project can be found here: https://github.com/RubenGres  
Inference endpoint for Seg2Map used on the demo available on rubengr.es/Seg2Sat


```python
import base64
import 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 handler
def 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 json
with open('payload.json', 'w') as f:
    json.dump(payload, f)

image_bytes = query(payload)

# You can access the image with PIL.Image for example
import io
from PIL import Image
image = Image.open(io.BytesIO(image_bytes))

image.save("output.png")

```