Fixed OCR decoding error - ensured indices are iterable
Browse files
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
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|