Spaces:
Runtime error
Runtime error
File size: 1,661 Bytes
3be2994 1f81651 3be2994 929c9f9 3be2994 929c9f9 200ac55 3be2994 bc0969b 93396af 3be2994 93396af 4f1a0f4 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 |
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 = "<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, .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) |