fashxp commited on
Commit
d25f24d
1 Parent(s): f62a5aa

initial commit

Browse files
Files changed (4) hide show
  1. .gitignore +3 -0
  2. README.md +38 -0
  3. handler.py +20 -0
  4. requirements.txt +1 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # PhpStorm / IDEA
2
+ .idea
3
+
README.md ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - vision
4
+ - image-to-image
5
+ - endpoints-template
6
+ - super-resolution
7
+ inference: false
8
+ pipeline_tag: image-to-image
9
+ library_name: generic
10
+ ---
11
+
12
+ # [DAT-x2](https://huggingface.co/OzzyGT/DAT_X2) for a `image-to-image` Inference endpoint.
13
+
14
+ > Inspired by https://huggingface.co/sergeipetrov/dat-x2-ie
15
+
16
+ This repository implements a `custom` task for `image-to-image` for 🤗 Inference Endpoints to allow image up scaling by doubling image resolution.
17
+ The code for the customized pipeline is in the handler.py.
18
+
19
+ To use deploy this model an Inference Endpoint you have to select `Custom` as task to use the `handler.py` file.
20
+
21
+ ### expected Request payload
22
+
23
+ Image to be labeled as binary.
24
+
25
+ #### CURL
26
+
27
+ ```
28
+ curl URL \
29
+ -X POST \
30
+ --data-binary @car.png \
31
+ -H "Content-Type: image/png"
32
+ ```
33
+
34
+ #### Python
35
+
36
+ ```python
37
+ requests.post(ENDPOINT_URL, headers={"Content-Type": "image/png"}, data=open("car.png", 'rb').read()).json()
38
+ ```
handler.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from image_gen_aux import UpscaleWithModel
2
+ import numpy as np
3
+ from PIL import Image
4
+ from io import BytesIO
5
+ import base64
6
+
7
+
8
+ class EndpointHandler():
9
+ def __init__(self, path=""):
10
+ self.upscaler = UpscaleWithModel.from_pretrained("OzzyGT/DAT_X2").to("cuda")
11
+
12
+ def __call__(self, data):
13
+ img = data.pop("inputs", data)
14
+ output = self.upscaler(img, tiling=True, tile_width=768, tile_height=768, overlap=8)
15
+
16
+ buffered = BytesIO()
17
+ output.save(buffered, format="JPEG")
18
+ img_str = base64.b64encode(buffered.getvalue())
19
+
20
+ return img_str.decode()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ git+https://github.com/asomoza/image_gen_aux.git