Tho Bui
update
6bccbd3
raw
history blame contribute delete
No virus
1.51 kB
import gradio as gr
from dotenv import load_dotenv, find_dotenv
import easyocr
_ = load_dotenv(find_dotenv())
out_textbox = gr.TextArea(
label="Output",
info="Data extracted",
lines=10,
value="",
interactive= True
)
def process(filepath):
reader = easyocr.Reader(['en'],gpu=True)
result = reader.readtext(filepath, batch_size=3)
latest_x = 0
latest_y = 0
content = ""
x_to_charactor = 0
for x,y,z in result:
current_x = x[0][0]
current_y = x[0][1]
if x_to_charactor == 0:
x_to_charactor = (x[1][0] - x[0][0])/(len(y))
if current_y - latest_y > 10:
content += f"""
"""
num_space = int((current_x - 0)/x_to_charactor)
if num_space > 1 and latest_x != 0:
for i in range(num_space):
content += f""" """
content += f"""{y}"""
else:
num_space = int((current_x - latest_x)/x_to_charactor)
if num_space > 1 and latest_x != 0:
for i in range(num_space):
content += f""" """
content += f""" {y}"""
latest_x = x[1][0]
latest_y = current_y
yield content
with gr.Blocks() as demo:
gr.Interface(
process,
[gr.Image(type="filepath")],
[out_textbox],
flagging_options=[],
examples=[]
)
demo.launch(server_name="0.0.0.0", server_port=7860)