Zhibinhong commited on
Commit
0e359f1
1 Parent(s): 75f23c2

Upload 2 files

Browse files
Files changed (2) hide show
  1. handler.py +49 -0
  2. requirements.txt +272 -0
handler.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from transformers import Pipeline
3
+ from PIL import Image
4
+ from io import BytesIO
5
+ import base64
6
+ import json
7
+ from visual_chatgpt import ImageEditing, Text2Box, Segmenting, Inpainting
8
+
9
+ class EndpointHandler():
10
+ def __init__(self, path=""):
11
+ # 换个顺序就行了?????离谱
12
+ self.sam = Segmenting('cuda')
13
+ self.inpaint = Inpainting('cuda')
14
+ self.grounding = Text2Box('cuda')
15
+ self.model = ImageEditing(self.grounding,self.sam,self.inpaint)
16
+ def __call__(self, data):
17
+ # data=json.loads(data)
18
+ # inputs=data.pop("inputs",data)
19
+ # inputs=base64.b64decode(inputs)
20
+ # raw_images = Image.open(BytesIO(inputs))
21
+ info=data['inputs']
22
+ image=info.pop('image',data)
23
+ image=base64.b64decode(image)
24
+ raw_image=Image.open(BytesIO(image)).convert('RGB')
25
+ target=info.pop('target',data)
26
+ replacement=info.pop('replacement',data)
27
+ if replacement=="":
28
+ return self.model.inference_remove(raw_image,target)
29
+ else:
30
+ return self.model.inference_replace_sam(raw_image,target,replacement)
31
+
32
+
33
+ if __name__=="__main__":
34
+ my_handler=EndpointHandler(path='.')
35
+ # test_payload={"inputs": "/home/ubuntu/guoling/1.png"}
36
+ with open("/home/ubuntu/guoling/1.png",'rb') as img:
37
+ image_bytes=img.read()
38
+ image_base64=base64.b64encode(image_bytes).decode('utf-8')
39
+ target="the pig"
40
+ replacement=""
41
+ data={
42
+ 'inputs':{
43
+ "image":image_base64,
44
+ "target":target,
45
+ "replacement":replacement
46
+ }
47
+ }
48
+ result=my_handler(data)
49
+ result.save("new1.png")
requirements.txt ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ absl-py==1.4.0
2
+ accelerate==0.18.0
3
+ addict==2.4.0
4
+ aiofiles==23.1.0
5
+ aiohttp==3.8.4
6
+ aiosignal==1.3.1
7
+ albumentations==1.3.0
8
+ altair==4.2.2
9
+ antlr4-python3-runtime==4.9.3
10
+ anyio==3.6.2
11
+ appdirs==1.4.4
12
+ asteroid==0.6.0
13
+ asteroid-filterbanks==0.4.0
14
+ asttokens==2.2.1
15
+ async-timeout==4.0.2
16
+ attrs==23.1.0
17
+ audioread==3.0.0
18
+ backcall==0.2.0
19
+ backports.zoneinfo==0.2.1
20
+ basicsr==1.4.2
21
+ blinker==1.6.2
22
+ braceexpand==0.1.7
23
+ cached-property==1.5.2
24
+ cachetools==5.3.0
25
+ certifi==2022.12.7
26
+ cffi==1.15.1
27
+ charset-normalizer==3.1.0
28
+ ci-sdr==0.0.2
29
+ click==8.1.3
30
+ cmake==3.26.3
31
+ coloredlogs==15.0.1
32
+ comm==0.1.3
33
+ ConfigArgParse==1.5.3
34
+ contourpy==1.0.7
35
+ controlnet-aux==0.0.1
36
+ ctc-segmentation==1.7.4
37
+ cycler==0.11.0
38
+ Cython==0.29.34
39
+ dataclasses-json==0.5.7
40
+ datasets==2.11.0
41
+ debugpy==1.6.7
42
+ decorator==5.1.1
43
+ diffusers==0.15.0.dev0
44
+ dill==0.3.6
45
+ Distance==0.1.3
46
+ editdistance==0.6.2
47
+ einops==0.6.1
48
+ entrypoints==0.4
49
+ espnet==202301
50
+ espnet-model-zoo==0.1.7
51
+ espnet-tts-frontend==0.0.3
52
+ executing==1.2.0
53
+ fast-bss-eval==0.1.3
54
+ fastapi==0.95.1
55
+ ffmpy==0.3.0
56
+ filelock==3.12.0
57
+ Flask==2.2.3
58
+ Flask-Cors==3.0.10
59
+ flatbuffers==23.3.3
60
+ fonttools==4.39.3
61
+ frozenlist==1.3.3
62
+ fsspec==2023.4.0
63
+ ftfy==6.1.1
64
+ future==0.18.3
65
+ g2p-en==2.1.0
66
+ gitdb==4.0.10
67
+ GitPython==3.1.31
68
+ google-auth==2.17.3
69
+ google-auth-oauthlib==1.0.0
70
+ gradio==3.27.0
71
+ gradio-client==0.1.3
72
+ greenlet==2.0.2
73
+ groundingdino==0.1.0
74
+ grpcio==1.54.0
75
+ h11==0.14.0
76
+ h5py==3.8.0
77
+ httpcore==0.17.0
78
+ httpx==0.24.0
79
+ huggingface-hub==0.13.4
80
+ humanfriendly==10.0
81
+ hydra-core==1.3.2
82
+ HyperPyYAML==1.2.0
83
+ idna==3.4
84
+ imageio==2.27.0
85
+ imageio-ffmpeg==0.4.8
86
+ importlib-metadata==4.9.0
87
+ importlib-resources==5.12.0
88
+ inflect==6.0.4
89
+ invisible-watermark==0.1.5
90
+ ipykernel==6.22.0
91
+ ipython==8.12.0
92
+ itsdangerous==2.1.2
93
+ jaconv==0.3.4
94
+ jamo==0.4.1
95
+ jedi==0.18.2
96
+ Jinja2==3.1.2
97
+ joblib==1.2.0
98
+ jsonschema==4.17.3
99
+ julius==0.2.7
100
+ jupyter-client==8.2.0
101
+ jupyter-core==5.3.0
102
+ kaldiio==2.18.0
103
+ kiwisolver==1.4.4
104
+ kornia==0.6.12
105
+ langchain==0.0.101
106
+ lazy-loader==0.2
107
+ librosa==0.10.0.post2
108
+ lightning-utilities==0.8.0
109
+ linkify-it-py==2.0.0
110
+ lit==16.0.1
111
+ llvmlite==0.39.1
112
+ lmdb==1.4.1
113
+ Markdown==3.4.3
114
+ markdown-it-py==2.2.0
115
+ MarkupSafe==2.1.2
116
+ marshmallow==3.19.0
117
+ marshmallow-enum==1.5.1
118
+ matplotlib==3.7.1
119
+ matplotlib-inline==0.1.6
120
+ mdit-py-plugins==0.3.3
121
+ mdurl==0.1.2
122
+ mir-eval==0.7
123
+ mpmath==1.3.0
124
+ msgpack==1.0.5
125
+ multidict==6.0.4
126
+ multiprocess==0.70.14
127
+ mypy-extensions==1.0.0
128
+ nest-asyncio==1.5.6
129
+ networkx==3.1
130
+ nltk==3.8.1
131
+ numba==0.56.4
132
+ numpy==1.23.0
133
+ nvidia-cublas-cu11==11.10.3.66
134
+ nvidia-cuda-cupti-cu11==11.7.101
135
+ nvidia-cuda-nvrtc-cu11==11.7.99
136
+ nvidia-cuda-runtime-cu11==11.7.99
137
+ nvidia-cudnn-cu11==8.5.0.96
138
+ nvidia-cufft-cu11==10.9.0.58
139
+ nvidia-curand-cu11==10.2.10.91
140
+ nvidia-cusolver-cu11==11.4.0.1
141
+ nvidia-cusparse-cu11==11.7.4.91
142
+ nvidia-nccl-cu11==2.14.3
143
+ nvidia-nvtx-cu11==11.7.91
144
+ oauthlib==3.2.2
145
+ omegaconf==2.3.0
146
+ onnx==1.13.1
147
+ onnxruntime==1.14.1
148
+ open-clip-torch==2.17.1
149
+ openai==0.27.4
150
+ opencv-python==4.7.0.72
151
+ opencv-python-headless==4.7.0.72
152
+ opt-einsum==3.3.0
153
+ orjson==3.8.10
154
+ packaging==23.1
155
+ pandas==2.0.0
156
+ parso==0.8.3
157
+ pb-bss-eval==0.0.2
158
+ pesq==0.0.4
159
+ pexpect==4.8.0
160
+ pickleshare==0.7.5
161
+ Pillow==9.5.0
162
+ pkgutil-resolve-name==1.3.10
163
+ platformdirs==3.2.0
164
+ pooch==1.6.0
165
+ prettytable==3.7.0
166
+ prompt-toolkit==3.0.38
167
+ protobuf==3.20.1
168
+ psutil==5.9.5
169
+ ptyprocess==0.7.0
170
+ pure-eval==0.2.2
171
+ pyarrow==11.0.0
172
+ pyasn1==0.5.0
173
+ pyasn1-modules==0.3.0
174
+ pycocotools==2.0.6
175
+ pycparser==2.21
176
+ pydantic==1.10.7
177
+ pydeck==0.8.1b0
178
+ pyDeprecate==0.3.2
179
+ pydub==0.25.1
180
+ Pygments==2.15.1
181
+ Pympler==1.0.1
182
+ pyparsing==3.0.9
183
+ pypinyin==0.44.0
184
+ pyrsistent==0.19.3
185
+ pystoi==0.3.3
186
+ pytesseract==0.3.10
187
+ python-dateutil==2.8.2
188
+ python-multipart==0.0.6
189
+ pytorch-lightning==2.0.1.post0
190
+ pytorch-ranger==0.1.1
191
+ pytorch-wpe==0.0.1
192
+ pytz==2023.3
193
+ pytz-deprecation-shim==0.1.0.post0
194
+ PyWavelets==1.4.1
195
+ pyworld==0.3.3
196
+ PyYAML==6.0
197
+ pyzmq==25.0.2
198
+ qudida==0.0.4
199
+ regex==2023.3.23
200
+ requests==2.28.2
201
+ requests-oauthlib==1.3.1
202
+ responses==0.18.0
203
+ rich==13.3.4
204
+ rsa==4.9
205
+ ruamel.yaml==0.17.21
206
+ ruamel.yaml.clib==0.2.7
207
+ safetensors==0.3.1
208
+ scikit-image==0.20.0
209
+ scikit-learn==1.2.2
210
+ scipy==1.9.0
211
+ segment-anything==1.0
212
+ semantic-version==2.10.0
213
+ sentencepiece==0.1.98
214
+ six==1.16.0
215
+ smmap==5.0.0
216
+ sniffio==1.3.0
217
+ soundfile==0.12.1
218
+ soxr==0.3.5
219
+ speechbrain==0.5.14
220
+ SQLAlchemy==1.4.47
221
+ stack-data==0.6.2
222
+ starlette==0.26.1
223
+ streamlit==1.21.0
224
+ supervision==0.6.0
225
+ sympy==1.11.1
226
+ tb-nightly==2.13.0a20230422
227
+ tenacity==8.2.2
228
+ tensorboard==2.12.2
229
+ tensorboard-data-server==0.7.0
230
+ tensorboard-plugin-wit==1.8.1
231
+ test-tube==0.7.5
232
+ threadpoolctl==3.1.0
233
+ tifffile==2023.4.12
234
+ tiktoken==0.3.3
235
+ timm==0.6.13
236
+ tokenizers==0.13.3
237
+ toml==0.10.2
238
+ tomli==2.0.1
239
+ toolz==0.12.0
240
+ torch==1.13.1
241
+ torch-complex==0.4.3
242
+ torch-optimizer==0.1.0
243
+ torch-stoi==0.1.2
244
+ torchaudio==2.0.1
245
+ torchmetrics==0.7.3
246
+ torchvision==0.14.1
247
+ tornado==6.3.1
248
+ tqdm==4.65.0
249
+ traitlets==5.9.0
250
+ transformers==4.28.0.dev0
251
+ triton==2.0.0
252
+ typeguard==2.13.3
253
+ typing-extensions==4.5.0
254
+ typing-inspect==0.8.0
255
+ tzdata==2023.3
256
+ tzlocal==4.3
257
+ uc-micro-py==1.0.1
258
+ Unidecode==1.3.6
259
+ urllib3==1.26.15
260
+ uvicorn==0.21.1
261
+ validators==0.20.0
262
+ waitress==2.1.2
263
+ watchdog==3.0.0
264
+ wcwidth==0.2.6
265
+ webdataset==0.2.48
266
+ websockets==11.0.2
267
+ Werkzeug==2.2.3
268
+ wget==3.2
269
+ xxhash==3.2.0
270
+ yapf==0.33.0
271
+ yarl==1.9.1
272
+ zipp==3.15.0