File size: 2,303 Bytes
244baab
 
 
 
 
 
 
 
 
 
c95f8ee
244baab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c95f8ee
244baab
 
 
c95f8ee
 
 
 
 
 
244baab
 
 
 
 
 
c95f8ee
244baab
c95f8ee
244baab
 
 
c95f8ee
244baab
 
 
 
 
c95f8ee
244baab
 
 
 
c95f8ee
244baab
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import io
import cv2
import requests
import numpy as np
import streamlit as st

from PIL import Image
from skimage.io import imread


def infer() -> None:
    st.title("IAM Handwriting recognition app")

    image_file_buffer = st.sidebar.file_uploader("Select input image", type=["png"])
    # read the image
    if image_file_buffer is not None:
        image = Image.open(image_file_buffer)
        image_array = np.array(image)
        st.image(image_array, caption=f"Input image: {image_file_buffer.name}")
    else:
        st.write("Input image: not selected")

    # run inference when the option is invoked by the user
    infer_button = st.sidebar.button("Run inference")
    if infer_button:
        files = {"image_file": (image_file_buffer.name, image_file_buffer.getvalue())}

        # if the deployment is on local machine
        response = requests.post(
            "https://abhishekrs4-handwriting-recognition.hf.space/predict",
            files=files,
        )

        # if the deployment is on hugging face
        # response = requests.post(
        #     "http://127.0.0.1:7860/predict",
        #     files=files,
        # )

        st.write("The following is the prediction")
        st.write(response.json())
    return


def app_info() -> None:
    st.title("App info")
    st.markdown("_Task - IAM Handwriting recognition_")
    st.markdown(
        "_Project repo - [https://github.com/AbhishekRS4/Handwriting_Recognition](https://github.com/AbhishekRS4/Handwriting_Recognition)_"
    )
    st.markdown(
        "_Dataset - [IAM dataset](https://fki.tic.heia-fr.ch/databases/iam-handwriting-database)_"
    )
    st.header("Brief description of the project")
    st.write("The IAM dataset contains images of handwritten text in English language.")
    st.write("A custom architecture is modeled for the recognition task.")
    st.write("The best performing model has been used for the deployed application.")
    return


app_modes = {
    "App Info": app_info,
    "IAM Handwriting Recognition Inference App": infer,
}


def start_app() -> None:
    selected_mode = st.sidebar.selectbox("Select mode", list(app_modes.keys()))
    app_modes[selected_mode]()
    return


def main() -> None:
    start_app()
    return


if __name__ == "__main__":
    main()