File size: 1,220 Bytes
e32cd03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62

import numpy as np
import streamlit as st
from PIL import Image, ImageOps
import cv2
from utils import OCR


alert = False
ocr = None

st.title("Optical Character Recognition")

tab_upload, tab_cam = st.tabs(['Upload', 'Camera'])

with tab_upload:
    image_upload = st.file_uploader(
        label='Upload the Image', type=['jpg', 'jpeg', 'png'])

with tab_cam:
    image_webcam = st.camera_input(
        label="Take a picture 📷")
if image_upload:
    image = Image.open(image_upload)
elif image_webcam:
    image = Image.open(image_webcam)
else:
    image = Image.open('./Images/sample_image_1.jpg')

st.image(image=ImageOps.scale(image, factor=0.2))

if st.button('Detect'):

    try:
        pass
        ocr = OCR(image=image)

    except:

        st.warning(
            " Please use a different image.", icon="⚠")
        alert = True


if ocr:
    st.caption("✨Result")

    try:
        st.pyplot(fig=ocr.detection(), use_container_width=True)
    except:
        st.warning(
            " Please use a different image", icon="⚠")


else:
    st.caption('Just click the Detect button')
    if alert:
        st.warning(
            " Please use a different image.", icon="⚠")

    st.image(image)