| import gradio | |
| import Levenshtein | |
| def calculate_distance(ocr_text, original_text): | |
| ocr_string = ocr_text.replace("\n"," ") | |
| original_string = original_text.replace("\n"," ") | |
| distance = Levenshtein.distance(ocr_string.lower(),original_string.lower()) | |
| cer = round(((distance/len(original_string))*100),2) | |
| accuracy = 100-cer | |
| return f"The Character Error Rate (CER): {cer}\nThe Accuracy: {accuracy}" | |
| iface = gradio.Interface( | |
| fn=calculate_distance, | |
| inputs=['text','text'], | |
| outputs='text', | |
| title='OCR Character Error Rate (CER) Calculation Using Levenshtein Distance ', | |
| description="In this space, you can enter the OCR text result and the original text to calculate ") | |
| iface.launch() |