Implemented OCR decoding for prescription text
Browse files
app.py
CHANGED
|
@@ -24,10 +24,16 @@ 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 |
|
| 28 |
# Placeholder function for decoding (depends on model architecture)
|
| 29 |
def decode_prediction(prediction):
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Gradio UI
|
| 33 |
interface = gr.Interface(
|
|
|
|
| 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
|
| 39 |
interface = gr.Interface(
|