English
Inference Endpoints
File size: 2,697 Bytes
d23c8e6
 
 
 
2be647f
d23c8e6
2be647f
 
 
 
 
 
 
 
 
 
d23c8e6
 
 
 
 
 
 
 
 
 
 
 
2be647f
d23c8e6
 
 
 
 
 
2be647f
d23c8e6
 
 
 
2be647f
d23c8e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2be647f
 
d23c8e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2be647f
d23c8e6
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/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",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "from handler import EndpointHandler\n",
    "import base64\n",
    "from io import BytesIO\n",
    "from PIL import Image\n",
    "import cv2\n",
    "import random\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://upscale-process-results.s3.amazonaws.com/1156995e-7c5f-4f0a-aa47-0dc8922f6f69.png 1156995e-7c5f-4f0a-aa47-0dc8922f6f69.png None\n"
     ]
    }
   ],
   "source": [
    "API_URL = \"https://po409l85y2ps6yo5.us-east-1.aws.endpoints.huggingface.cloud\"\n",
    "headers = {\n",
    "\t\"Accept\" : \"application/json\",\n",
    "\t\"Content-Type\": \"application/json\" \n",
    "}\n",
    "\n",
    "img_dir = \"test_data/\"\n",
    "img_names = [\"4121783.png\", \"FB_IMG_1725931665635.jpg\", \"FB_IMG_1725931665635_gray.jpg\"]\n",
    "out_scales = [10, 3, 5.49]\n",
    "for img_name, outscale in zip(img_names, out_scales):\n",
    "\timage_path = img_dir + img_name\n",
    "\t# create payload\n",
    "\twith open(image_path, \"rb\") as i:\n",
    "\t\tb64 = base64.b64encode(i.read())\n",
    "\t\tb64 = b64.decode(\"utf-8\")\n",
    "\t\tpayload = {\"inputs\": {\"image\": b64, \"outscale\": outscale}}\n",
    "\t\t\n",
    "\tresponse = requests.post(API_URL, headers=headers, json=payload)\n",
    "\toutput_payload = response.json()\t\n",
    "\tprint(output_payload['image_url'], output_payload['image_key'], output_payload['error'])\n",
    "\tbreak"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "diffusers",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}