murtazadahmardeh commited on
Commit
c1332c7
·
1 Parent(s): d70af8b

image blob

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -23,18 +23,26 @@ class App:
23
  return model
24
 
25
  @torch.inference_mode()
26
- def __call__(self, model_name, image):
27
- if image is None:
28
  return '', []
 
 
 
 
 
29
  model = self._get_model(model_name)
30
- image = self._preprocess(image.convert('RGB')).unsqueeze(0)
 
31
  # Greedy decoding
32
  pred = model(image).softmax(-1)
33
  label, _ = model.tokenizer.decode(pred)
34
  raw_label, raw_confidence = model.tokenizer.decode(pred, raw=True)
 
35
  # Format confidence values
36
  max_len = 25 if model_name == 'crnn' else len(label[0]) + 1
37
  conf = list(map('{:0.1f}'.format, raw_confidence[0][:max_len].tolist()))
 
38
  return label[0], [raw_label[0][:max_len], conf]
39
 
40
 
 
23
  return model
24
 
25
  @torch.inference_mode()
26
+ def __call__(self, model_name, image_blob):
27
+ if image_blob is None:
28
  return '', []
29
+
30
+ # Decode base64 image blob and convert to PIL Image
31
+ image_data = base64.b64decode(image_blob)
32
+ image = Image.open(BytesIO(image_data)).convert('RGB')
33
+
34
  model = self._get_model(model_name)
35
+ image = self._preprocess(image).unsqueeze(0)
36
+
37
  # Greedy decoding
38
  pred = model(image).softmax(-1)
39
  label, _ = model.tokenizer.decode(pred)
40
  raw_label, raw_confidence = model.tokenizer.decode(pred, raw=True)
41
+
42
  # Format confidence values
43
  max_len = 25 if model_name == 'crnn' else len(label[0]) + 1
44
  conf = list(map('{:0.1f}'.format, raw_confidence[0][:max_len].tolist()))
45
+
46
  return label[0], [raw_label[0][:max_len], conf]
47
 
48