English
Inference Endpoints
garg-aayush commited on
Commit
2be647f
1 Parent(s): a84e2f3

No tiling commit for S3 save url and name

Browse files
Files changed (3) hide show
  1. handler.py +4 -3
  2. test_api_endpoint.ipynb +17 -24
  3. test_handler.ipynb +11 -30
handler.py CHANGED
@@ -31,8 +31,8 @@ class EndpointHandler:
31
  num_grow_ch=32,
32
  scale=4
33
  ),
34
- tile=1000,
35
- tile_pad=20,
36
  half=True,
37
  )
38
 
@@ -43,7 +43,8 @@ class EndpointHandler:
43
  )
44
  # Get the S3 bucket name from environment variables
45
  self.bucket_name = os.environ["S3_BUCKET_NAME"]
46
-
 
47
  def __call__(self, data: Any) -> Dict[str, List[float]]:
48
 
49
  try:
 
31
  num_grow_ch=32,
32
  scale=4
33
  ),
34
+ tile=0,
35
+ tile_pad=0,
36
  half=True,
37
  )
38
 
 
43
  )
44
  # Get the S3 bucket name from environment variables
45
  self.bucket_name = os.environ["S3_BUCKET_NAME"]
46
+
47
+
48
  def __call__(self, data: Any) -> Dict[str, List[float]]:
49
 
50
  try:
test_api_endpoint.ipynb CHANGED
@@ -2,9 +2,18 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 36,
6
  "metadata": {},
7
- "outputs": [],
 
 
 
 
 
 
 
 
 
8
  "source": [
9
  "from handler import EndpointHandler\n",
10
  "import base64\n",
@@ -17,34 +26,19 @@
17
  },
18
  {
19
  "cell_type": "code",
20
- "execution_count": 35,
21
- "metadata": {},
22
- "outputs": [],
23
- "source": [
24
- "# helper decoder\n",
25
- "def decode_base64_image(image_string):\n",
26
- " base64_image = base64.b64decode(image_string)\n",
27
- " buffer = BytesIO(base64_image)\n",
28
- " return Image.open(buffer)\n"
29
- ]
30
- },
31
- {
32
- "cell_type": "code",
33
- "execution_count": 37,
34
  "metadata": {},
35
  "outputs": [
36
  {
37
  "name": "stdout",
38
  "output_type": "stream",
39
  "text": [
40
- "out_image.size: (12000, 5170)\n",
41
- "out_image.size: (3168, 3204)\n",
42
- "out_image.size: (5797, 5863)\n"
43
  ]
44
  }
45
  ],
46
  "source": [
47
- "API_URL = \"https://s3pbd8dbht1g91w4.us-east-1.aws.endpoints.huggingface.cloud\"\n",
48
  "headers = {\n",
49
  "\t\"Accept\" : \"application/json\",\n",
50
  "\t\"Content-Type\": \"application/json\" \n",
@@ -63,9 +57,8 @@
63
  "\t\t\n",
64
  "\tresponse = requests.post(API_URL, headers=headers, json=payload)\n",
65
  "\toutput_payload = response.json()\t\n",
66
- "\tout_image = decode_base64_image(output_payload[\"out_image\"])\n",
67
- "\tprint(f\"out_image.size: {out_image.size}\")\n",
68
- "\tout_image.save(f\"test_data/{img_name.split('.')[0]}_outscale_{outscale}.png\")\n"
69
  ]
70
  },
71
  {
@@ -92,7 +85,7 @@
92
  "name": "python",
93
  "nbconvert_exporter": "python",
94
  "pygments_lexer": "ipython3",
95
- "version": "3.10.13"
96
  }
97
  },
98
  "nbformat": 4,
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
  "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stderr",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "/usr/local/lib/python3.10/dist-packages/torchvision/transforms/functional_tensor.py:5: UserWarning: The torchvision.transforms.functional_tensor module is deprecated in 0.15 and will be **removed in 0.17**. Please don't rely on it. You probably just need to use APIs in torchvision.transforms.functional or in torchvision.transforms.v2.functional.\n",
13
+ " warnings.warn(\n"
14
+ ]
15
+ }
16
+ ],
17
  "source": [
18
  "from handler import EndpointHandler\n",
19
  "import base64\n",
 
26
  },
27
  {
28
  "cell_type": "code",
29
+ "execution_count": 2,
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  "metadata": {},
31
  "outputs": [
32
  {
33
  "name": "stdout",
34
  "output_type": "stream",
35
  "text": [
36
+ "https://upscale-process-results.s3.amazonaws.com/1156995e-7c5f-4f0a-aa47-0dc8922f6f69.png 1156995e-7c5f-4f0a-aa47-0dc8922f6f69.png None\n"
 
 
37
  ]
38
  }
39
  ],
40
  "source": [
41
+ "API_URL = \"https://po409l85y2ps6yo5.us-east-1.aws.endpoints.huggingface.cloud\"\n",
42
  "headers = {\n",
43
  "\t\"Accept\" : \"application/json\",\n",
44
  "\t\"Content-Type\": \"application/json\" \n",
 
57
  "\t\t\n",
58
  "\tresponse = requests.post(API_URL, headers=headers, json=payload)\n",
59
  "\toutput_payload = response.json()\t\n",
60
+ "\tprint(output_payload['image_url'], output_payload['image_key'], output_payload['error'])\n",
61
+ "\tbreak"
 
62
  ]
63
  },
64
  {
 
85
  "name": "python",
86
  "nbconvert_exporter": "python",
87
  "pygments_lexer": "ipython3",
88
+ "version": "3.10.12"
89
  }
90
  },
91
  "nbformat": 4,
test_handler.ipynb CHANGED
@@ -28,19 +28,6 @@
28
  "execution_count": 2,
29
  "metadata": {},
30
  "outputs": [],
31
- "source": [
32
- "# helper decoder\n",
33
- "def decode_base64_image(image_string):\n",
34
- " base64_image = base64.b64decode(image_string)\n",
35
- " buffer = BytesIO(base64_image)\n",
36
- " return Image.open(buffer)"
37
- ]
38
- },
39
- {
40
- "cell_type": "code",
41
- "execution_count": 3,
42
- "metadata": {},
43
- "outputs": [],
44
  "source": [
45
  "# init handler\n",
46
  "my_handler = EndpointHandler(path=\".\")"
@@ -48,7 +35,7 @@
48
  },
49
  {
50
  "cell_type": "code",
51
- "execution_count": 5,
52
  "metadata": {},
53
  "outputs": [
54
  {
@@ -62,11 +49,14 @@
62
  "name": "stdout",
63
  "output_type": "stream",
64
  "text": [
65
- "\tTile 1/2\n",
66
- "\tTile 2/2\n",
67
- "\tTile 1/2\n",
68
- "\tTile 2/2\n",
69
- "output.shape: (5170, 12000, 4)\n"
 
 
 
70
  ]
71
  }
72
  ],
@@ -88,18 +78,9 @@
88
  "\n",
89
  "\n",
90
  " output_payload = my_handler(payload)\n",
91
- " # out_image = decode_base64_image(output_payload[\"out_image\"])\n",
92
- " # print(f\"out_image.size: {out_image.size}\")\n",
93
- " # out_image.save(f\"test_data/outputs/{img_name.split('.')[0]}_outscale_{outscale}.png\")\n",
94
- " break"
95
  ]
96
- },
97
- {
98
- "cell_type": "code",
99
- "execution_count": null,
100
- "metadata": {},
101
- "outputs": [],
102
- "source": []
103
  }
104
  ],
105
  "metadata": {
 
28
  "execution_count": 2,
29
  "metadata": {},
30
  "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  "source": [
32
  "# init handler\n",
33
  "my_handler = EndpointHandler(path=\".\")"
 
35
  },
36
  {
37
  "cell_type": "code",
38
+ "execution_count": 4,
39
  "metadata": {},
40
  "outputs": [
41
  {
 
49
  "name": "stdout",
50
  "output_type": "stream",
51
  "text": [
52
+ "output.shape: (5170, 12000, 4)\n",
53
+ "https://upscale-process-results.s3.amazonaws.com/0da01291-5a39-40fd-b322-f5d83e6066f6.png 0da01291-5a39-40fd-b322-f5d83e6066f6.png\n",
54
+ "image.size: (1056, 1068), image.mode: RGB, outscale: 3.0\n",
55
+ "output.shape: (3204, 3168, 3)\n",
56
+ "https://upscale-process-results.s3.amazonaws.com/c1ba714d-50e2-45d0-ac9f-8a4a4f218320.png c1ba714d-50e2-45d0-ac9f-8a4a4f218320.png\n",
57
+ "image.size: (1056, 1068), image.mode: L, outscale: 5.49\n",
58
+ "output.shape: (5863, 5797, 3)\n",
59
+ "https://upscale-process-results.s3.amazonaws.com/e964c021-9169-49d8-9382-104f704a1d92.png e964c021-9169-49d8-9382-104f704a1d92.png\n"
60
  ]
61
  }
62
  ],
 
78
  "\n",
79
  "\n",
80
  " output_payload = my_handler(payload)\n",
81
+ " print(output_payload[\"image_url\"], output_payload[\"image_key\"])\n",
82
+ " "
 
 
83
  ]
 
 
 
 
 
 
 
84
  }
85
  ],
86
  "metadata": {