abhishekrs4
commited on
Commit
•
244baab
1
Parent(s):
e191ffa
added streamlit frontend application
Browse files- frontend.py +70 -0
frontend.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import io
|
3 |
+
import cv2
|
4 |
+
import requests
|
5 |
+
import numpy as np
|
6 |
+
import streamlit as st
|
7 |
+
|
8 |
+
from PIL import Image
|
9 |
+
from skimage.io import imread
|
10 |
+
|
11 |
+
def infer() -> None:
|
12 |
+
st.title("IAM Handwriting recognition app")
|
13 |
+
|
14 |
+
image_file_buffer = st.sidebar.file_uploader("Select input image", type=["png"])
|
15 |
+
# read the image
|
16 |
+
if image_file_buffer is not None:
|
17 |
+
image = Image.open(image_file_buffer)
|
18 |
+
image_array = np.array(image)
|
19 |
+
st.image(image_array, caption=f"Input image: {image_file_buffer.name}")
|
20 |
+
else:
|
21 |
+
st.write("Input image: not selected")
|
22 |
+
|
23 |
+
# run inference when the option is invoked by the user
|
24 |
+
infer_button = st.sidebar.button("Run inference")
|
25 |
+
if infer_button:
|
26 |
+
files = {"image_file": (image_file_buffer.name, image_file_buffer.getvalue())}
|
27 |
+
|
28 |
+
# if the deployment is on local machine
|
29 |
+
response = requests.post(
|
30 |
+
"https://abhishekrs4-handwriting-recognition.hf.space/predict",
|
31 |
+
files=files,
|
32 |
+
)
|
33 |
+
|
34 |
+
# if the deployment is on hugging face
|
35 |
+
# response = requests.post(
|
36 |
+
# "http://127.0.0.1:7860/predict",
|
37 |
+
# files=files,
|
38 |
+
# )
|
39 |
+
|
40 |
+
st.write("The following is the prediction")
|
41 |
+
st.write(response.json())
|
42 |
+
return
|
43 |
+
|
44 |
+
def app_info() -> None:
|
45 |
+
st.title("App info")
|
46 |
+
st.markdown("_Task - IAM Handwriting recognition_")
|
47 |
+
st.markdown("_Project repo - [https://github.com/AbhishekRS4/Handwriting_Recognition](https://github.com/AbhishekRS4/Handwriting_Recognition)_")
|
48 |
+
st.markdown("_Dataset - [IAM dataset](https://fki.tic.heia-fr.ch/databases/iam-handwriting-database)_")
|
49 |
+
st.header("Brief description of the project")
|
50 |
+
st.write("The IAM dataset contains images of handwritten text in English language.")
|
51 |
+
st.write("A custom architecture is modeled for the recognition task.")
|
52 |
+
st.write("The best performing model has been used for the deployed application.")
|
53 |
+
return
|
54 |
+
|
55 |
+
app_modes = {
|
56 |
+
"App Info" : app_info,
|
57 |
+
"IAM Handwriting Recognition Inference App": infer,
|
58 |
+
}
|
59 |
+
|
60 |
+
def start_app() -> None:
|
61 |
+
selected_mode = st.sidebar.selectbox("Select mode", list(app_modes.keys()))
|
62 |
+
app_modes[selected_mode]()
|
63 |
+
return
|
64 |
+
|
65 |
+
def main() -> None:
|
66 |
+
start_app()
|
67 |
+
return
|
68 |
+
|
69 |
+
if __name__ == "__main__":
|
70 |
+
main()
|