|
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"]) |
|
|
|
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") |
|
|
|
|
|
infer_button = st.sidebar.button("Run inference") |
|
if infer_button: |
|
files = {"image_file": (image_file_buffer.name, image_file_buffer.getvalue())} |
|
|
|
|
|
response = requests.post( |
|
"https://abhishekrs4-handwriting-recognition.hf.space/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() |
|
|