i-dont-hug-face commited on
Commit
27b2057
1 Parent(s): 86209be

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +1 -5
inference.py CHANGED
@@ -1,9 +1,7 @@
1
- import os
2
  import torch
3
  import re
4
  from PIL import Image
5
  from transformers import DonutProcessor, VisionEncoderDecoderModel
6
- import base64
7
  import io
8
  import json
9
 
@@ -17,9 +15,7 @@ def model_fn(model_dir, context=None):
17
  def transform_fn(model, request_body, request_content_type, response_content_type, context=None):
18
  model, processor, device = model
19
  if request_content_type == 'application/json':
20
- data = json.loads(request_body)
21
- image_data = data['inputs']
22
- image = Image.open(io.BytesIO(base64.b64decode(image_data))).convert("RGB")
23
 
24
  # Preprocess the image
25
  pixel_values = processor(image, return_tensors="pt").pixel_values.to(device)
 
 
1
  import torch
2
  import re
3
  from PIL import Image
4
  from transformers import DonutProcessor, VisionEncoderDecoderModel
 
5
  import io
6
  import json
7
 
 
15
  def transform_fn(model, request_body, request_content_type, response_content_type, context=None):
16
  model, processor, device = model
17
  if request_content_type == 'application/json':
18
+ image = Image.open(io.BytesIO(request_body))
 
 
19
 
20
  # Preprocess the image
21
  pixel_values = processor(image, return_tensors="pt").pixel_values.to(device)