Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,68 @@ import gradio as gr
|
|
| 2 |
import easyocr
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def detect_lang_ocr(img,lang):
|
| 7 |
try:
|
|
|
|
| 8 |
reader = easyocr.Reader(lang)
|
| 9 |
bounds = reader.readtext(img)
|
| 10 |
tot_b = len(bounds)
|
|
@@ -24,7 +83,7 @@ with gr.Blocks() as app:
|
|
| 24 |
|
| 25 |
im = gr.Image(type = "filepath")
|
| 26 |
ocr_sens=gr.Slider(0.1, 1, step=0.05,value=0.25,label="Detect Min Confidence")
|
| 27 |
-
lang = gr.Textbox(visible=
|
| 28 |
max_tok=gr.Number(label="Max Tokens",step=1, value=200)
|
| 29 |
det_btn = gr.Button()
|
| 30 |
det_out = gr.Textbox()
|
|
|
|
| 2 |
import easyocr
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
+
ocr_id = {
|
| 6 |
+
"Afrikaans": "af",
|
| 7 |
+
"Albanian": "sq",
|
| 8 |
+
"Arabic": "ar",
|
| 9 |
+
"Azerbaijani": "az",
|
| 10 |
+
"Belarusian": "be",
|
| 11 |
+
"Bulgarian": "bg",
|
| 12 |
+
"Bengali": "bn",
|
| 13 |
+
"Bosnian": "bs",
|
| 14 |
+
"Chinese (simplified)": "ch_sim",
|
| 15 |
+
"Chinese (traditional)": "ch_tra",
|
| 16 |
+
"Croatian": "hr",
|
| 17 |
+
"Czech": "cs",
|
| 18 |
+
"Danish": "da",
|
| 19 |
+
"Dutch": "nl",
|
| 20 |
+
"English": "en",
|
| 21 |
+
"Estonian": "et",
|
| 22 |
+
"French": "fr",
|
| 23 |
+
"German": "de",
|
| 24 |
+
"Irish": "ga",
|
| 25 |
+
"Hindi": "hi",
|
| 26 |
+
"Hungarian": "hu",
|
| 27 |
+
"Indonesian": "id",
|
| 28 |
+
"Icelandic": "is",
|
| 29 |
+
"Italian": "it",
|
| 30 |
+
"Japanese": "ja",
|
| 31 |
+
"Kannada": "kn",
|
| 32 |
+
"Korean": "ko",
|
| 33 |
+
"Lithuanian": "lt",
|
| 34 |
+
"Latvian": "lv",
|
| 35 |
+
"Mongolian": "mn",
|
| 36 |
+
"Marathi": "mr",
|
| 37 |
+
"Malay": "ms",
|
| 38 |
+
"Nepali": "ne",
|
| 39 |
+
"Norwegian": "no",
|
| 40 |
+
"Occitan": "oc",
|
| 41 |
+
"Polish": "pl",
|
| 42 |
+
"Portuguese": "pt",
|
| 43 |
+
"Romanian": "ro",
|
| 44 |
+
"Russian": "ru",
|
| 45 |
+
"Serbian (cyrillic)": "rs_cyrillic",
|
| 46 |
+
"Serbian (latin)": "rs_latin",
|
| 47 |
+
"Slovak": "sk",
|
| 48 |
+
"Slovenian": "sl",
|
| 49 |
+
"Spanish": "es",
|
| 50 |
+
"Swedish": "sv",
|
| 51 |
+
"Swahili": "sw",
|
| 52 |
+
"Tamil": "ta",
|
| 53 |
+
"Thai": "th",
|
| 54 |
+
"Tagalog": "tl",
|
| 55 |
+
"Turkish": "tr",
|
| 56 |
+
"Ukrainian": "uk",
|
| 57 |
+
"Urdu": "ur",
|
| 58 |
+
"Uzbek": "uz",
|
| 59 |
+
"Vietnamese": "vi",
|
| 60 |
+
"Welsh": "cy",
|
| 61 |
+
"Zulu": "zu",
|
| 62 |
+
}
|
| 63 |
|
| 64 |
def detect_lang_ocr(img,lang):
|
| 65 |
try:
|
| 66 |
+
lang = [f'{lang}']
|
| 67 |
reader = easyocr.Reader(lang)
|
| 68 |
bounds = reader.readtext(img)
|
| 69 |
tot_b = len(bounds)
|
|
|
|
| 83 |
|
| 84 |
im = gr.Image(type = "filepath")
|
| 85 |
ocr_sens=gr.Slider(0.1, 1, step=0.05,value=0.25,label="Detect Min Confidence")
|
| 86 |
+
lang = gr.Textbox(visible=True)
|
| 87 |
max_tok=gr.Number(label="Max Tokens",step=1, value=200)
|
| 88 |
det_btn = gr.Button()
|
| 89 |
det_out = gr.Textbox()
|