| | import os |
| | |
| | os.system('wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb') |
| | os.system('dpkg -i libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb') |
| | os.system('pip install paddlepaddle') |
| | os.system('pip install paddleocr') |
| | from paddleocr import PaddleOCR, draw_ocr |
| | from PIL import Image |
| | import gradio as gr |
| | import torch |
| | import matplotlib.pylab as plt |
| | import numpy as np |
| |
|
| | torch.hub.download_url_to_file('https://i.imgur.com/aqMBT0i.jpg', 'example.jpg') |
| |
|
| | DISPLAY_WIDTH = 40 |
| | CYCLES = [20, 60, 100, 140, 180, 220] |
| | PIXEL = '█' |
| | EMPTY = ' ' |
| |
|
| |
|
| |
|
| | def solve(img): |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | img_path = img.name |
| | |
| | ocr = PaddleOCR(use_angle_cls=True, use_gpu=False) |
| | result = ocr.ocr(img_path, cls=True)[0] |
| | image = Image.open(img_path).convert('RGB') |
| | boxes = [line[0] for line in result] |
| | txts = [line[1][0] for line in result] |
| | scores = [line[1][1] for line in result] |
| | |
| | |
| | |
| | |
| | return txts, img |
| |
|
| | title = 'Cathode-Ray Tube' |
| | description = 'Day 10 2022 AoC using OCR!!!' |
| | article = "<p style='text-align: center'>Day 10 2022 AoC using OCR!!!</p>" |
| | css = ".output_image {height: 40rem !important; width: 100% !important;}" |
| | gr.Interface( |
| | solve, |
| | [gr.inputs.Image(type='file', label='Input')], |
| | [gr.Textbox(label="OCR result"), gr.outputs.Image(type='file', label='OCR image')], |
| | title=title, |
| | description=description, |
| | article=article, |
| | css=css, |
| | enable_queue=True |
| | ).launch(debug=True) |