File size: 2,378 Bytes
3be2994
 
 
 
 
1f81651
3be2994
 
 
929c9f9
3be2994
 
 
 
 
 
 
 
929c9f9
200ac55
3be2994
 
f0bd9c4
3c69971
 
f0bd9c4
4bcbb35
 
06d4c29
f0bd9c4
a914705
41efcc2
3be2994
bc0969b
 
96d14c9
93396af
cd52228
 
3be2994
 
 
 
 
 
a914705
c5e531e
3be2994
 
 
93396af
3be2994
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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) 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)