Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -11,6 +11,12 @@ from transformers import (
|
|
| 11 |
)
|
| 12 |
import numpy as np
|
| 13 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
from IndicTransToolkit import IndicProcessor
|
| 16 |
|
|
@@ -107,6 +113,7 @@ def process_image(image):
|
|
| 107 |
# # Recognize text in the cropped area
|
| 108 |
# recognized_text = ocr.recognise(cropped_path, script_lang)
|
| 109 |
# recognized_texts.append(recognized_text)
|
|
|
|
| 110 |
for id, bbox in enumerate(detections):
|
| 111 |
# Identify the script and crop the image to this region
|
| 112 |
script_lang, cropped_path = ocr.crop_and_identify_script(pil_image, bbox)
|
|
@@ -120,13 +127,14 @@ def process_image(image):
|
|
| 120 |
if script_lang:
|
| 121 |
recognized_text = ocr.recognise(cropped_path, script_lang)
|
| 122 |
recognized_texts[f"img_{id}"] = {"txt": recognized_text, "bbox": [x1, y1, x2, y2]}
|
|
|
|
| 123 |
|
| 124 |
# Combine recognized texts into a single string for display
|
| 125 |
# recognized_texts_combined = " ".join(recognized_texts)
|
| 126 |
string = detect_para(recognized_texts)
|
| 127 |
|
| 128 |
recognized_texts_combined = '\n'.join([' '.join(line) for line in string])
|
| 129 |
-
recognized_texts_combined = translate(recognized_texts_combined,
|
| 130 |
|
| 131 |
return output_image, recognized_texts_combined
|
| 132 |
|
|
|
|
| 11 |
)
|
| 12 |
import numpy as np
|
| 13 |
import torch
|
| 14 |
+
from collections import Counter
|
| 15 |
+
|
| 16 |
+
def Most_Common(lst):
|
| 17 |
+
data = Counter(lst)
|
| 18 |
+
return data.most_common(1)[0][0]
|
| 19 |
+
|
| 20 |
|
| 21 |
from IndicTransToolkit import IndicProcessor
|
| 22 |
|
|
|
|
| 113 |
# # Recognize text in the cropped area
|
| 114 |
# recognized_text = ocr.recognise(cropped_path, script_lang)
|
| 115 |
# recognized_texts.append(recognized_text)
|
| 116 |
+
langs = []
|
| 117 |
for id, bbox in enumerate(detections):
|
| 118 |
# Identify the script and crop the image to this region
|
| 119 |
script_lang, cropped_path = ocr.crop_and_identify_script(pil_image, bbox)
|
|
|
|
| 127 |
if script_lang:
|
| 128 |
recognized_text = ocr.recognise(cropped_path, script_lang)
|
| 129 |
recognized_texts[f"img_{id}"] = {"txt": recognized_text, "bbox": [x1, y1, x2, y2]}
|
| 130 |
+
langs.append(script_lang)
|
| 131 |
|
| 132 |
# Combine recognized texts into a single string for display
|
| 133 |
# recognized_texts_combined = " ".join(recognized_texts)
|
| 134 |
string = detect_para(recognized_texts)
|
| 135 |
|
| 136 |
recognized_texts_combined = '\n'.join([' '.join(line) for line in string])
|
| 137 |
+
recognized_texts_combined = translate(recognized_texts_combined,Most_Common(langs))
|
| 138 |
|
| 139 |
return output_image, recognized_texts_combined
|
| 140 |
|