Spaces:
Runtime error
Runtime error
Commit
·
f1eee64
1
Parent(s):
ea4455d
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,16 @@ init_session_states()
|
|
24 |
import easyocr
|
25 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
|
|
|
|
|
|
|
|
|
28 |
|
29 |
def main():
|
30 |
|
@@ -35,14 +44,12 @@ def main():
|
|
35 |
st.write(file_details)
|
36 |
image = load_image(uploaded_file)
|
37 |
st.image(image,width=500)
|
38 |
-
|
39 |
-
st.write("Detecting text...")
|
40 |
reader = easyocr.Reader(['en'],gpu=True)
|
41 |
bound = reader.readtext(image)
|
42 |
-
st.write("Detection complete")
|
43 |
st.write(str(bound))
|
44 |
-
|
45 |
-
|
46 |
|
47 |
|
48 |
|
|
|
24 |
import easyocr
|
25 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
26 |
|
27 |
+
def text_recognition(image):
|
28 |
+
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
|
29 |
+
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
|
30 |
+
#processor = TrOCRProcessor.from_pretrained("microsoft/trocr-large-handwritten")
|
31 |
+
#model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-large-handwritten")
|
32 |
|
33 |
+
pixel_values = processor(image, return_tensors="pt").pixel_values
|
34 |
+
generated_ids = model.generate(pixel_values)
|
35 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
36 |
+
st.write(generated_text)
|
37 |
|
38 |
def main():
|
39 |
|
|
|
44 |
st.write(file_details)
|
45 |
image = load_image(uploaded_file)
|
46 |
st.image(image,width=500)
|
47 |
+
st.write("Detecting text bounding box...")
|
|
|
48 |
reader = easyocr.Reader(['en'],gpu=True)
|
49 |
bound = reader.readtext(image)
|
50 |
+
st.write("Bounding box Detection complete")
|
51 |
st.write(str(bound))
|
52 |
+
text_recognition(image)
|
|
|
53 |
|
54 |
|
55 |
|