bha-ocr / app.py
3v324v23's picture
wip
24caf2f
import streamlit as st
from PIL import Image, ImageDraw, ImageFont
import json
import os
import cv2
from utils import draw_ocr_results, start_ocr
def get_image_path(img):
# Create a directory and save the uploaded image.
file_path = f"data/uploadedImages/{img.name}"
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, "wb") as img_file:
img_file.write(img.getbuffer())
return file_path
uploaded_file = st.file_uploader("**Upload a Chest X-Ray Image**", type= ['png', 'jpg'] )
if uploaded_file is not None:
# Get actual image file
fpath= get_image_path(uploaded_file)
# st.image(fpath)
res = start_ocr({
'image_dir': fpath,
'drop_score': 0.3,
#'det_model_dir': "./paddle/ch_PP-OCRv3_det_infer",
'det_model_dir': "./paddle/ch_PP-OCRv4_det_infer",
#'det_model_dir': "./paddle/ch_PP-OCRv4_det_server_infer",
#'rec_model_dir': "./paddle/ch_PP-OCRv3_rec_infer",
'rec_model_dir': "./paddle/ch_PP-OCRv4_rec_infer",
#'rec_model_dir': "./paddle/ch_PP-OCRv4_rec_server_infer",
'det_limit_side_len': 2496,
"det_db_box_thresh": 0.2,
"use_angle_cls": False,
#"cls_model_dir": "./paddle/ch_ppocr_mobile_v2.0_cls_infer",
"rec_char_dict_path": './paddle/ppocr_keys_v1.txt',
"show_log": True,
})
st.image(draw_ocr_results(
Image.fromarray(
cv2.imread(fpath))
, res[0], './fonts/simfang.ttf'))