Dramb commited on
Commit
f116c1f
·
verified ·
1 Parent(s): ac29793

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +26 -8
inference.py CHANGED
@@ -1,16 +1,34 @@
1
  from PIL import Image
2
  import numpy as np
 
 
3
 
4
- class Pipeline: # <--- обязательно Pipeline
5
  def __init__(self, path=""):
6
- print("Model initialized")
7
 
8
  def __call__(self, inputs):
9
- image = inputs.get("image")
10
 
11
- if isinstance(image, str):
12
- from base64 import b64decode
13
- from io import BytesIO
14
- image = Image.open(BytesIO(b64decode(image)))
 
15
 
16
- return {"msg": "Got image", "size": image.size}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from PIL import Image
2
  import numpy as np
3
+ import base64
4
+ from io import BytesIO
5
 
6
+ class Pipeline:
7
  def __init__(self, path=""):
8
+ print("Pipeline initialized")
9
 
10
  def __call__(self, inputs):
11
+ image_data = inputs.get("image")
12
 
13
+ if isinstance(image_data, str):
14
+ image_bytes = base64.b64decode(image_data)
15
+ image = Image.open(BytesIO(image_bytes))
16
+ else:
17
+ return {"error": "No image provided"}
18
 
19
+ width, height = image.size
20
+
21
+ # Пример простой маски: прямоугольник по центру
22
+ mask = np.zeros((height, width), dtype=np.uint8)
23
+ mask[height//4: 3*height//4, width//4: 3*width//4] = 1
24
+
25
+ # Преобразуем в обычный Python-список
26
+ mask_list = mask.tolist()
27
+
28
+ return [
29
+ {
30
+ "label": "mock-segment",
31
+ "mask": mask_list,
32
+ "score": 0.99
33
+ }
34
+ ]