import pandas as pd import PIL from PIL import Image from PIL import ImageDraw import gradio as gr import torch import easyocr def draw_boxes(image, bounds, color='green', width=2): draw = ImageDraw.Draw(image) for bound in bounds: p0, p1, p2, p3 = bound[0] draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width) return image def inference(img, lang): reader = easyocr.Reader(lang) bounds = reader.readtext(img, paragraph = True) im = PIL.Image.open(img) draw_boxes(im, bounds) im.save('result.jpg') return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]] title = 'سحب النصوص من الصور (خاص في تطبيقات أبشر)' description = 'هذه مثال لكيفية سحب النصوص من صور شاشات من تطبيق أبشر للمساعدة في إكتشاف الأخطاء التي قد تظهر للمستخدمين' article = "

" examples = [['./e1.jpg',['ar','en']],['./e2.jpg',['ar','en']], ['./e3.jpg',['ar','en']], ['./e4.jpg',['ar','en']], ['./e5.jpg',['ar','en']]] css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}" choices = [ "ar", "en", ] gr.Interface( inference, [gr.inputs.Image(type='filepath', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['en'], label='language')], [gr.outputs.Image(type='filepath', label='Output'), gr.outputs.Dataframe(headers=['text', 'confidence'], type="pandas")], title=title, description=description, article=article, examples=examples, css=css, enable_queue=True ).launch(debug=True)