OrderAndChaos
commited on
Commit
•
f687f36
1
Parent(s):
81e209a
Update README.md
Browse files
README.md
CHANGED
@@ -13,6 +13,76 @@ duplicated_from: lllyasviel/control_v11p_sd15_inpaint
|
|
13 |
pipeline_tag: other
|
14 |
---
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Controlnet - v1.1 - *InPaint Version*
|
17 |
|
18 |
**Controlnet v1.1** was released in [lllyasviel/ControlNet-v1-1](https://huggingface.co/lllyasviel/ControlNet-v1-1) by [Lvmin Zhang](https://huggingface.co/lllyasviel).
|
|
|
13 |
pipeline_tag: other
|
14 |
---
|
15 |
|
16 |
+
# Usage
|
17 |
+
|
18 |
+
```python
|
19 |
+
import base64
|
20 |
+
|
21 |
+
import requests
|
22 |
+
|
23 |
+
HF_TOKEN = 'hf_xxxxxxxxxxxxx'
|
24 |
+
API_ENDPOINT = 'https://xxxxxxxxxxx.us-east-1.aws.endpoints.huggingface.cloud'
|
25 |
+
|
26 |
+
def load_image(path):
|
27 |
+
try:
|
28 |
+
with open(path, 'rb') as file:
|
29 |
+
return file.read()
|
30 |
+
except FileNotFoundError as error:
|
31 |
+
print('Error reading image:', error)
|
32 |
+
|
33 |
+
|
34 |
+
def get_b64_image(path):
|
35 |
+
image_buffer = load_image(path)
|
36 |
+
if image_buffer:
|
37 |
+
return base64.b64encode(image_buffer).decode('utf-8')
|
38 |
+
|
39 |
+
|
40 |
+
def process_images(original_image_path, mask_image_path, result_path, prompt, width, height):
|
41 |
+
original_b64 = get_b64_image(original_image_path)
|
42 |
+
mask_b64 = get_b64_image(mask_image_path)
|
43 |
+
|
44 |
+
if not original_b64 or not mask_b64:
|
45 |
+
return
|
46 |
+
|
47 |
+
body = {
|
48 |
+
'inputs': prompt,
|
49 |
+
'image': original_b64,
|
50 |
+
'mask_image': mask_b64,
|
51 |
+
'width': width,
|
52 |
+
'height': height
|
53 |
+
}
|
54 |
+
|
55 |
+
headers = {
|
56 |
+
'Authorization': f'Bearer {HF_TOKEN}',
|
57 |
+
'Content-Type': 'application/json',
|
58 |
+
'Accept': 'image/png'
|
59 |
+
}
|
60 |
+
|
61 |
+
response = requests.post(
|
62 |
+
API_ENDPOINT,
|
63 |
+
json=body,
|
64 |
+
headers=headers
|
65 |
+
)
|
66 |
+
blob = response.content
|
67 |
+
|
68 |
+
save_image(blob, result_path)
|
69 |
+
|
70 |
+
|
71 |
+
def save_image(blob, file_path):
|
72 |
+
with open(file_path, 'wb') as file:
|
73 |
+
file.write(blob)
|
74 |
+
print('File saved successfully!')
|
75 |
+
|
76 |
+
|
77 |
+
if __name__ == '__main__':
|
78 |
+
original_image_path = 'images/original.png'
|
79 |
+
mask_image_path = 'images/mask.png'
|
80 |
+
result_path = 'images/result.png'
|
81 |
+
process_images(original_image_path, mask_image_path, result_path, 'cyberpunk mona lisa', 512, 768)
|
82 |
+
|
83 |
+
```
|
84 |
+
|
85 |
+
|
86 |
# Controlnet - v1.1 - *InPaint Version*
|
87 |
|
88 |
**Controlnet v1.1** was released in [lllyasviel/ControlNet-v1-1](https://huggingface.co/lllyasviel/ControlNet-v1-1) by [Lvmin Zhang](https://huggingface.co/lllyasviel).
|