import gradio as gr import os #from googletrans import Translator import easyocr #import PIL from PIL import Image from PIL import ImageDraw def Get_OCR_demo(image): reader = easyocr.Reader(['en']) #IMP 'hi' translator = Translator() #image_file =Image.open(image,mode = 'r') im = Image.open(image,mode = 'r') #im =Image.open(image,mode = 'r') text_list = reader.readtext(im,add_margin = 0.55,width_ths=0.7, link_threshold=0.8,decoder='beamsearch', blocklist='=-',detail = 0 ) #text_list = reader.readtext(image_file,add_margin = 0.55,width_ths=0.7, link_threshold=0.8,decoder='beamsearch', blocklist='=-',detail = 0 ) text_comb =' '.join(text_list) #changed into a single line return text_comb title = "Upload an image and extract Text from it" description = "OCR tool for text extraction" examples=[["english.png"],["Upload Parag_Letter_j.jpg"]] get_OCR_demo = gr.Interface(fn=Get_OCR_demo, inputs="image",outputs=['text'],title = title,description=description,examples=[["english.png","Parag_Letter.jfif"]],cache_examples=False) # if __name__ == "__main__": # demo.launch()