stshanks commited on
Commit
2e72fc2
·
1 Parent(s): acdb8c9

Fixed OCR decoding error - ensured indices are iterable

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -24,15 +24,23 @@ def predict_text(image):
24
  print(prediction) # Check what the model is outputting
25
  predicted_text = decode_prediction(prediction) # Implement your decoding logic
26
  return predicted_text
 
27
  import string
 
28
 
29
  # Define possible characters in prescriptions (letters, numbers, etc.)
30
  CHARACTER_SET = string.ascii_letters + string.digits + " .,-/()"
31
 
32
- # Placeholder function for decoding (depends on model architecture)
33
  def decode_prediction(prediction):
34
- indices = np.argmax(prediction, axis=-1) # Get index of highest probability for each character
35
- text = "".join([CHARACTER_SET[i] for i in indices[0]]) # Convert indices to characters
 
 
 
 
 
 
 
36
  return text
37
 
38
  # Gradio UI
 
24
  print(prediction) # Check what the model is outputting
25
  predicted_text = decode_prediction(prediction) # Implement your decoding logic
26
  return predicted_text
27
+
28
  import string
29
+ import numpy as np
30
 
31
  # Define possible characters in prescriptions (letters, numbers, etc.)
32
  CHARACTER_SET = string.ascii_letters + string.digits + " .,-/()"
33
 
 
34
  def decode_prediction(prediction):
35
+ indices = np.argmax(prediction, axis=-1) # Get indices of highest probabilities
36
+
37
+ # Ensure indices is iterable (check if it's a single number or array)
38
+ if indices.ndim == 1: # If it's a 1D array
39
+ indices = indices.tolist() # Convert to a list
40
+ elif indices.ndim == 0: # If it's a single number
41
+ indices = [indices.item()] # Wrap it in a list
42
+
43
+ text = "".join([CHARACTER_SET[i] for i in indices]) # Convert indices to characters
44
  return text
45
 
46
  # Gradio UI