Upload folder using huggingface_hub
Browse files- README.md +50 -0
- handdrawn.png +0 -0
- handler.py +1 -1
- output.png +0 -0
- test_endpoint.py +44 -0
README.md
CHANGED
@@ -8,3 +8,53 @@ inference: true
|
|
8 |
---
|
9 |
|
10 |
# 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
---
|
9 |
|
10 |
# 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)
|
11 |
+
|
12 |
+
You can call the inference endpoint like this :
|
13 |
+
|
14 |
+
```
|
15 |
+
import base64
|
16 |
+
import requests
|
17 |
+
|
18 |
+
API_URL = "https://zqz606ggn85ysase.us-east-1.aws.endpoints.huggingface.cloud"
|
19 |
+
|
20 |
+
def encode_image(image_path):
|
21 |
+
with open(image_path, "rb") as i:
|
22 |
+
b64 = base64.b64encode(i.read())
|
23 |
+
return b64.decode("utf-8")
|
24 |
+
|
25 |
+
prompt = "aerial view of jardin princier, Toulouse. Flowers, flowers, garden"
|
26 |
+
image = encode_image("handdrawn.png")
|
27 |
+
|
28 |
+
|
29 |
+
headers = {
|
30 |
+
"Accept": "image/png",
|
31 |
+
"Content-Type": "application/json"
|
32 |
+
}
|
33 |
+
|
34 |
+
# test the handler
|
35 |
+
def query(payload):
|
36 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
37 |
+
return response.content
|
38 |
+
|
39 |
+
payload = {
|
40 |
+
"inputs": prompt,
|
41 |
+
"prompt": prompt,
|
42 |
+
"image": image,
|
43 |
+
"steps": 20,
|
44 |
+
"seed": 999
|
45 |
+
}
|
46 |
+
|
47 |
+
import json
|
48 |
+
with open('payload.json', 'w') as f:
|
49 |
+
json.dump(payload, f)
|
50 |
+
|
51 |
+
image_bytes = query(payload)
|
52 |
+
|
53 |
+
# You can access the image with PIL.Image for example
|
54 |
+
import io
|
55 |
+
from PIL import Image
|
56 |
+
image = Image.open(io.BytesIO(image_bytes))
|
57 |
+
|
58 |
+
image.save("output.png")
|
59 |
+
|
60 |
+
```
|
handdrawn.png
ADDED
handler.py
CHANGED
@@ -40,7 +40,7 @@ class EndpointHandler():
|
|
40 |
# decode image
|
41 |
image = self.decode_base64_image(image)
|
42 |
|
43 |
-
self.generator = torch.Generator(device="cpu").manual_seed(
|
44 |
|
45 |
# run inference pipeline
|
46 |
image_out = self.pipe(
|
|
|
40 |
# decode image
|
41 |
image = self.decode_base64_image(image)
|
42 |
|
43 |
+
self.generator = torch.Generator(device="cpu").manual_seed(seed)
|
44 |
|
45 |
# run inference pipeline
|
46 |
image_out = self.pipe(
|
output.png
ADDED
test_endpoint.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import base64
|
2 |
+
import requests
|
3 |
+
|
4 |
+
API_URL = "https://zqz606ggn85ysase.us-east-1.aws.endpoints.huggingface.cloud"
|
5 |
+
|
6 |
+
def encode_image(image_path):
|
7 |
+
with open(image_path, "rb") as i:
|
8 |
+
b64 = base64.b64encode(i.read())
|
9 |
+
return b64.decode("utf-8")
|
10 |
+
|
11 |
+
prompt = "aerial view of jardin princier, Toulouse. Flowers, flowers, garden"
|
12 |
+
image = encode_image("handdrawn.png")
|
13 |
+
|
14 |
+
|
15 |
+
headers = {
|
16 |
+
"Accept": "image/png",
|
17 |
+
"Content-Type": "application/json"
|
18 |
+
}
|
19 |
+
|
20 |
+
# test the handler
|
21 |
+
def query(payload):
|
22 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
23 |
+
return response.content
|
24 |
+
|
25 |
+
payload = {
|
26 |
+
"inputs": prompt,
|
27 |
+
"prompt": prompt,
|
28 |
+
"image": image,
|
29 |
+
"steps": 20,
|
30 |
+
"seed": 999
|
31 |
+
}
|
32 |
+
|
33 |
+
import json
|
34 |
+
with open('payload.json', 'w') as f:
|
35 |
+
json.dump(payload, f)
|
36 |
+
|
37 |
+
image_bytes = query(payload)
|
38 |
+
|
39 |
+
# You can access the image with PIL.Image for example
|
40 |
+
import io
|
41 |
+
from PIL import Image
|
42 |
+
image = Image.open(io.BytesIO(image_bytes))
|
43 |
+
|
44 |
+
image.save("output.png")
|