Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,10 @@ from transformers import AutoProcessor
|
|
24 |
model = SeamlessM4TForTextToText.from_pretrained("facebook/hf-seamless-m4t-medium")
|
25 |
processor = AutoProcessor.from_pretrained("facebook/hf-seamless-m4t-medium")
|
26 |
|
|
|
|
|
|
|
|
|
27 |
# OCR Predictor initialization
|
28 |
OCRpredictor = ocr_predictor(det_arch='db_mobilenet_v3_large', reco_arch='crnn_vgg16_bn', pretrained=True)
|
29 |
|
@@ -65,19 +69,24 @@ def process_text_in_chunks(text, process_function, max_chunk_size=256):
|
|
65 |
return processed_text.strip()
|
66 |
@spaces.GPU(duration=120)
|
67 |
def greet(img, apply_grammar_correction, apply_spell_check):
|
68 |
-
img.save("out.jpg")
|
69 |
-
doc = DocumentFile.from_images("out.jpg")
|
70 |
-
output = OCRpredictor(doc)
|
71 |
-
|
72 |
-
res = ""
|
73 |
-
for obj in output.pages:
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
81 |
# Process in chunks for grammar correction
|
82 |
if apply_grammar_correction:
|
83 |
res = process_text_in_chunks(res, lambda x: happy_tt.generate_text("grammar: " + x, args=grammar_args).text)
|
|
|
24 |
model = SeamlessM4TForTextToText.from_pretrained("facebook/hf-seamless-m4t-medium")
|
25 |
processor = AutoProcessor.from_pretrained("facebook/hf-seamless-m4t-medium")
|
26 |
|
27 |
+
|
28 |
+
import pytesseract as pt
|
29 |
+
import cv2
|
30 |
+
|
31 |
# OCR Predictor initialization
|
32 |
OCRpredictor = ocr_predictor(det_arch='db_mobilenet_v3_large', reco_arch='crnn_vgg16_bn', pretrained=True)
|
33 |
|
|
|
69 |
return processed_text.strip()
|
70 |
@spaces.GPU(duration=120)
|
71 |
def greet(img, apply_grammar_correction, apply_spell_check):
|
72 |
+
# img.save("out.jpg")
|
73 |
+
# doc = DocumentFile.from_images("out.jpg")
|
74 |
+
# output = OCRpredictor(doc)
|
75 |
+
|
76 |
+
# res = ""
|
77 |
+
# for obj in output.pages:
|
78 |
+
# for obj1 in obj.blocks:
|
79 |
+
# for obj2 in obj1.lines:
|
80 |
+
# for obj3 in obj2.words:
|
81 |
+
# res += " " + obj3.value
|
82 |
+
# res += "\n"
|
83 |
+
# res += "\n"
|
84 |
+
|
85 |
+
|
86 |
+
# img = cv2.imread(inputPath)
|
87 |
+
res = pt.image_to_string(img,lang='eng')
|
88 |
+
# print(text)
|
89 |
+
|
90 |
# Process in chunks for grammar correction
|
91 |
if apply_grammar_correction:
|
92 |
res = process_text_in_chunks(res, lambda x: happy_tt.generate_text("grammar: " + x, args=grammar_args).text)
|