garg-aayush
commited on
Commit
•
d23c8e6
1
Parent(s):
a69442a
add test_api_endpoint.ipynb
Browse files- Untitled-1.ipynb +0 -74
- test_api_endpoint.ipynb +100 -0
Untitled-1.ipynb
DELETED
@@ -1,74 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": 4,
|
6 |
-
"metadata": {},
|
7 |
-
"outputs": [
|
8 |
-
{
|
9 |
-
"ename": "ModuleNotFoundError",
|
10 |
-
"evalue": "No module named 'torchvision.transforms.functional_tensor'",
|
11 |
-
"output_type": "error",
|
12 |
-
"traceback": [
|
13 |
-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
14 |
-
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
15 |
-
"Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mhandler\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m EndpointHandler\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m# init handler\u001b[39;00m\n\u001b[1;32m 4\u001b[0m my_handler \u001b[38;5;241m=\u001b[39m EndpointHandler(path\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
16 |
-
"File \u001b[0;32m~/repos/real-esrgan/handler.py:4\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mPIL\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Image\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mio\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BytesIO\n\u001b[0;32m----> 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mrealesrgan\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m RealESRGANer\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtyping\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Dict, List, Any\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m\n",
|
17 |
-
"File \u001b[0;32m~/pkgs/miniconda3/envs/diffusers/lib/python3.10/site-packages/realesrgan/__init__.py:2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# flake8: noqa\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01marchs\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdata\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodels\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n",
|
18 |
-
"File \u001b[0;32m~/pkgs/miniconda3/envs/diffusers/lib/python3.10/site-packages/realesrgan/archs/__init__.py:2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mimportlib\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbasicsr\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m scandir\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m path \u001b[38;5;28;01mas\u001b[39;00m osp\n\u001b[1;32m 5\u001b[0m \u001b[38;5;66;03m# automatically scan and import arch modules for registry\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;66;03m# scan all the files that end with '_arch.py' under the archs folder\u001b[39;00m\n",
|
19 |
-
"File \u001b[0;32m~/pkgs/miniconda3/envs/diffusers/lib/python3.10/site-packages/basicsr/__init__.py:4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# https://github.com/xinntao/BasicSR\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;66;03m# flake8: noqa\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01marchs\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[0;32m----> 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdata\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mlosses\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmetrics\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n",
|
20 |
-
"File \u001b[0;32m~/pkgs/miniconda3/envs/diffusers/lib/python3.10/site-packages/basicsr/data/__init__.py:22\u001b[0m\n\u001b[1;32m 20\u001b[0m dataset_filenames \u001b[38;5;241m=\u001b[39m [osp\u001b[38;5;241m.\u001b[39msplitext(osp\u001b[38;5;241m.\u001b[39mbasename(v))[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;28;01mfor\u001b[39;00m v \u001b[38;5;129;01min\u001b[39;00m scandir(data_folder) \u001b[38;5;28;01mif\u001b[39;00m v\u001b[38;5;241m.\u001b[39mendswith(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_dataset.py\u001b[39m\u001b[38;5;124m'\u001b[39m)]\n\u001b[1;32m 21\u001b[0m \u001b[38;5;66;03m# import all the dataset modules\u001b[39;00m\n\u001b[0;32m---> 22\u001b[0m _dataset_modules \u001b[38;5;241m=\u001b[39m [importlib\u001b[38;5;241m.\u001b[39mimport_module(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbasicsr.data.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfile_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m file_name \u001b[38;5;129;01min\u001b[39;00m dataset_filenames]\n\u001b[1;32m 25\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mbuild_dataset\u001b[39m(dataset_opt):\n\u001b[1;32m 26\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Build dataset from options.\u001b[39;00m\n\u001b[1;32m 27\u001b[0m \n\u001b[1;32m 28\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[38;5;124;03m type (str): Dataset type.\u001b[39;00m\n\u001b[1;32m 32\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n",
|
21 |
-
"File \u001b[0;32m~/pkgs/miniconda3/envs/diffusers/lib/python3.10/site-packages/basicsr/data/__init__.py:22\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 20\u001b[0m dataset_filenames \u001b[38;5;241m=\u001b[39m [osp\u001b[38;5;241m.\u001b[39msplitext(osp\u001b[38;5;241m.\u001b[39mbasename(v))[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;28;01mfor\u001b[39;00m v \u001b[38;5;129;01min\u001b[39;00m scandir(data_folder) \u001b[38;5;28;01mif\u001b[39;00m v\u001b[38;5;241m.\u001b[39mendswith(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_dataset.py\u001b[39m\u001b[38;5;124m'\u001b[39m)]\n\u001b[1;32m 21\u001b[0m \u001b[38;5;66;03m# import all the dataset modules\u001b[39;00m\n\u001b[0;32m---> 22\u001b[0m _dataset_modules \u001b[38;5;241m=\u001b[39m [\u001b[43mimportlib\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mimport_module\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mbasicsr.data.\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mfile_name\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m file_name \u001b[38;5;129;01min\u001b[39;00m dataset_filenames]\n\u001b[1;32m 25\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mbuild_dataset\u001b[39m(dataset_opt):\n\u001b[1;32m 26\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Build dataset from options.\u001b[39;00m\n\u001b[1;32m 27\u001b[0m \n\u001b[1;32m 28\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[38;5;124;03m type (str): Dataset type.\u001b[39;00m\n\u001b[1;32m 32\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n",
|
22 |
-
"File \u001b[0;32m~/pkgs/miniconda3/envs/diffusers/lib/python3.10/importlib/__init__.py:126\u001b[0m, in \u001b[0;36mimport_module\u001b[0;34m(name, package)\u001b[0m\n\u001b[1;32m 124\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[1;32m 125\u001b[0m level \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[0;32m--> 126\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_bootstrap\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_gcd_import\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m[\u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m:\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpackage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m)\u001b[49m\n",
|
23 |
-
"File \u001b[0;32m~/pkgs/miniconda3/envs/diffusers/lib/python3.10/site-packages/basicsr/data/realesrgan_dataset.py:11\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mtorch\u001b[39;00m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtorch\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m data \u001b[38;5;28;01mas\u001b[39;00m data\n\u001b[0;32m---> 11\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbasicsr\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdata\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdegradations\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m circular_lowpass_kernel, random_mixed_kernels\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbasicsr\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdata\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtransforms\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m augment\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbasicsr\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m FileClient, get_root_logger, imfrombytes, img2tensor\n",
|
24 |
-
"File \u001b[0;32m~/pkgs/miniconda3/envs/diffusers/lib/python3.10/site-packages/basicsr/data/degradations.py:8\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mscipy\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m special\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mscipy\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mstats\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m multivariate_normal\n\u001b[0;32m----> 8\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtorchvision\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtransforms\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mfunctional_tensor\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m rgb_to_grayscale\n\u001b[1;32m 10\u001b[0m \u001b[38;5;66;03m# -------------------------------------------------------------------- #\u001b[39;00m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;66;03m# --------------------------- blur kernels --------------------------- #\u001b[39;00m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;66;03m# -------------------------------------------------------------------- #\u001b[39;00m\n\u001b[1;32m 13\u001b[0m \n\u001b[1;32m 14\u001b[0m \n\u001b[1;32m 15\u001b[0m \u001b[38;5;66;03m# --------------------------- util functions --------------------------- #\u001b[39;00m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msigma_matrix2\u001b[39m(sig_x, sig_y, theta):\n",
|
25 |
-
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'torchvision.transforms.functional_tensor'"
|
26 |
-
]
|
27 |
-
}
|
28 |
-
],
|
29 |
-
"source": [
|
30 |
-
"from handler import EndpointHandler\n",
|
31 |
-
"\n",
|
32 |
-
"# init handler\n",
|
33 |
-
"my_handler = EndpointHandler(path=\".\")"
|
34 |
-
]
|
35 |
-
},
|
36 |
-
{
|
37 |
-
"cell_type": "code",
|
38 |
-
"execution_count": 3,
|
39 |
-
"metadata": {},
|
40 |
-
"outputs": [],
|
41 |
-
"source": [
|
42 |
-
"#!pip install --no-cache-dir realesrgan"
|
43 |
-
]
|
44 |
-
},
|
45 |
-
{
|
46 |
-
"cell_type": "code",
|
47 |
-
"execution_count": null,
|
48 |
-
"metadata": {},
|
49 |
-
"outputs": [],
|
50 |
-
"source": []
|
51 |
-
}
|
52 |
-
],
|
53 |
-
"metadata": {
|
54 |
-
"kernelspec": {
|
55 |
-
"display_name": "diffusers",
|
56 |
-
"language": "python",
|
57 |
-
"name": "python3"
|
58 |
-
},
|
59 |
-
"language_info": {
|
60 |
-
"codemirror_mode": {
|
61 |
-
"name": "ipython",
|
62 |
-
"version": 3
|
63 |
-
},
|
64 |
-
"file_extension": ".py",
|
65 |
-
"mimetype": "text/x-python",
|
66 |
-
"name": "python",
|
67 |
-
"nbconvert_exporter": "python",
|
68 |
-
"pygments_lexer": "ipython3",
|
69 |
-
"version": "3.10.13"
|
70 |
-
}
|
71 |
-
},
|
72 |
-
"nbformat": 4,
|
73 |
-
"nbformat_minor": 2
|
74 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_api_endpoint.ipynb
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
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",
|
11 |
+
"from io import BytesIO\n",
|
12 |
+
"from PIL import Image\n",
|
13 |
+
"import cv2\n",
|
14 |
+
"import random\n",
|
15 |
+
"import requests"
|
16 |
+
]
|
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",
|
51 |
+
"}\n",
|
52 |
+
"\n",
|
53 |
+
"img_dir = \"test_data/\"\n",
|
54 |
+
"img_names = [\"4121783.png\", \"FB_IMG_1725931665635.jpg\", \"FB_IMG_1725931665635_gray.jpg\"]\n",
|
55 |
+
"out_scales = [10, 3, 5.49]\n",
|
56 |
+
"for img_name, outscale in zip(img_names, out_scales):\n",
|
57 |
+
"\timage_path = img_dir + img_name\n",
|
58 |
+
"\t# create payload\n",
|
59 |
+
"\twith open(image_path, \"rb\") as i:\n",
|
60 |
+
"\t\tb64 = base64.b64encode(i.read())\n",
|
61 |
+
"\t\tb64 = b64.decode(\"utf-8\")\n",
|
62 |
+
"\t\tpayload = {\"inputs\": {\"image\": b64, \"outscale\": outscale}}\n",
|
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 |
+
{
|
72 |
+
"cell_type": "code",
|
73 |
+
"execution_count": null,
|
74 |
+
"metadata": {},
|
75 |
+
"outputs": [],
|
76 |
+
"source": []
|
77 |
+
}
|
78 |
+
],
|
79 |
+
"metadata": {
|
80 |
+
"kernelspec": {
|
81 |
+
"display_name": "diffusers",
|
82 |
+
"language": "python",
|
83 |
+
"name": "python3"
|
84 |
+
},
|
85 |
+
"language_info": {
|
86 |
+
"codemirror_mode": {
|
87 |
+
"name": "ipython",
|
88 |
+
"version": 3
|
89 |
+
},
|
90 |
+
"file_extension": ".py",
|
91 |
+
"mimetype": "text/x-python",
|
92 |
+
"name": "python",
|
93 |
+
"nbconvert_exporter": "python",
|
94 |
+
"pygments_lexer": "ipython3",
|
95 |
+
"version": "3.10.13"
|
96 |
+
}
|
97 |
+
},
|
98 |
+
"nbformat": 4,
|
99 |
+
"nbformat_minor": 2
|
100 |
+
}
|