English
Inference Endpoints
garg-aayush commited on
Commit
26cb0ac
1 Parent(s): a3912af

update handler file

Browse files
Untitled-1.ipynb ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
__pycache__/handler.cpython-310.pyc ADDED
Binary file (1.82 kB). View file
 
handler.py CHANGED
@@ -32,14 +32,14 @@ class EndpointHandler:
32
  # gpu_id=args.gpu_id
33
  )
34
 
35
- def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
36
- # def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
37
- image = data.pop("inputs", data)
38
- print(image)
39
  outscale = 3
 
 
 
40
  # Convert PIL image to NumPy array
41
  opencv_image = np.array(image)
42
-
43
  # Convert RGB to BGR (PIL uses RGB, OpenCV expects BGR)
44
  opencv_image = cv2.cvtColor(opencv_image, cv2.COLOR_RGB2BGR)
45
  output, _ = self.model.enhance(opencv_image, outscale=outscale)
 
32
  # gpu_id=args.gpu_id
33
  )
34
 
35
+ def __call__(self, data: Any) -> Dict[str, List[float]]:
36
+ inputs = data.pop("inputs", data)
 
 
37
  outscale = 3
38
+
39
+ # decode base64 image to PIL
40
+ image = Image.open(BytesIO(base64.b64decode(inputs['image'])))
41
  # Convert PIL image to NumPy array
42
  opencv_image = np.array(image)
 
43
  # Convert RGB to BGR (PIL uses RGB, OpenCV expects BGR)
44
  opencv_image = cv2.cvtColor(opencv_image, cv2.COLOR_RGB2BGR)
45
  output, _ = self.model.enhance(opencv_image, outscale=outscale)
test_hander.py ADDED
File without changes