File size: 1,716 Bytes
03484ca
 
51273bc
03484ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3a3645
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
47
48
49
50
51
52
53
54
import streamlit as st
from PIL import Image
import os
#Trick to not init function multitime
if "ocr_detector" not in st.session_state:
    print("INIT MODEL")
    from src.setup import Setup
    Setup().ocr_model_downloader()
    
    from src.OCR import OCRDetector
    st.session_state.ocr_detector = OCRDetector()
    print("DONE INIT MODEL")

st.set_page_config(page_title="Vietnamese OCR", layout="wide", page_icon = "./storage/linhai.jpeg")
hide_menu_style = """
<style>
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_menu_style, unsafe_allow_html= True)

st.markdown(
    """
    <style>
    [data-testid="stSidebar"][aria-expanded="true"] > div:first-child{
        width: 400px;
    }
    [data-testid="stSidebar"][aria-expanded="false"] > div:first-child{
        margin-left: -400px;
    }
     
    """,
    unsafe_allow_html=True,
)

st.markdown("<h2 style='text-align: center; color: grey;'>Input: Image </h2>", unsafe_allow_html=True)
st.markdown("<h2 style='text-align: center; color: grey;'>Output: The Vietnamese or English text in the image (if any).</h2>", unsafe_allow_html=True)
left_col, right_col = st.columns(2)

#LEFT COLUMN
upload_image = left_col.file_uploader("Choose an image file", type=["jpg", "jpeg", "png", "webp", ])

if left_col.button("OCR Detect"):
    image, texts, boxes = st.session_state.ocr_detector.text_detector(upload_image, is_local=True)
    left_col.write("**RESULTS:** ")
    left_col.write(texts)
    
    #RIGHT COLUMN
    visualize_image = st.session_state.ocr_detector.visualize_ocr(image, texts, boxes)
    right_col.write("**ORIGIN IMAGE:** ")
    right_col.image(image)
    right_col.write("**OCR IMAGE:** ")
    right_col.image(visualize_image)