File size: 1,435 Bytes
822c5ae
a9ee30e
866dcbc
f37284b
 
866dcbc
822c5ae
f37284b
 
 
 
 
 
 
 
 
 
 
bdc12ec
4a9ef07
866dcbc
 
 
 
 
 
5b29af7
866dcbc
 
 
 
 
 
 
 
 
 
 
 
 
a9ee30e
 
 
df8208d
24caf2f
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
45
46
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'))