Spaces:
Sleeping
Sleeping
import pandas as pd | |
import numpy as np | |
import PIL | |
from PIL import Image | |
from PIL import ImageDraw | |
import gradio as gr | |
import torch | |
import easyocr | |
import io | |
import base64 | |
def draw_boxes(image, bounds, color='red', 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.name) | |
im = PIL.Image.open(img.name) | |
draw_boxes(im, bounds) | |
im.save('result.jpg') | |
np_arr = np.array(im) | |
gr.Textbox(np_arr.shape) | |
#result_buffer = io.BytesIO() | |
return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]] | |
choices = ["en", "vi"] | |
#gr.Interface( | |
# inference, | |
# inputs=[gr.Image(label='Input'), | |
# gr.CheckboxGroup(choices, type="value", label='language')], | |
# outputs=[gr.Image(label='Output'), | |
# gr.Dataframe(headers=['text', 'confidence'])] | |
# ).launch(debug=True) | |
gr.Interface( | |
inference, | |
inputs=[gr.Image(label='Input'), | |
gr.CheckboxGroup(choices, type="value", label='language')], | |
outputs=gr.Image(label='Output') | |
).launch(debug=True) |