Spaces:
Runtime error
Runtime error
| 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') | |
| letter = "" | |
| resss = pd.DataFrame(bounds).iloc[: , 1:] | |
| for (name, data) in resss.iteritems(): | |
| for d in data: | |
| if ("رمز" in d) : | |
| letter = d | |
| if ("عفو" in d) or ("عذر" in d) or ("لا يوجد" in d) or ("من فضلك" in d): | |
| letter = d | |
| break | |
| return ['result.jpg', letter] | |
| title = 'سحب النصوص من الصور (خاص في تطبيقات أبشر)' | |
| description = 'هذه مثال لكيفية سحب النصوص من صور شاشات من تطبيق أبشر للمساعدة في إكتشاف الأخطاء التي قد تظهر للمستخدمين' | |
| article = "<p style='text-align: center'>هذه مثال لكيفية سحب النصوص من صور شاشات من تطبيق أبشر للمساعدة في إكتشاف الأخطاء التي قد تظهر للمستخدمين</p>" | |
| examples = [['./e1.jpg',['ar','en']],['./e2.jpg',['ar','en']], ['./e3.jpg',['ar','en']], ['./e4.jpg',['ar','en']], ['./e5.jpg',['ar','en']]] | |
| #css = ".output_image {height: 20rem !important; width: 100% !important;}, .input_image {height: 20rem !important; width: 100% !important;}" | |
| css = ".output-image, .input-image, .image-preview {height: 600px !important}" | |
| choices = [ | |
| "ar", | |
| "en", | |
| ] | |
| gr.Interface( | |
| inference, | |
| [gr.inputs.Image(type='filepath', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['ar'], label='language')], | |
| [gr.outputs.Image(type='filepath', label='Output').style(height=400, width=400), gr.outputs.Textbox( type="text", label="الخطأ المستخرج من الصورة: ")], | |
| title=title, | |
| description=description, | |
| article=article, | |
| examples=examples, | |
| css=css, | |
| enable_queue=True | |
| ).launch(debug=True) |