Spaces:
Sleeping
Sleeping
File size: 2,433 Bytes
c245399 07738b3 c245399 9198199 794a732 b2fe7c6 3864753 794a732 698fcad bae448a fa20230 794a732 2554770 b2fe7c6 03adfe3 47d42b8 78f8450 9198199 187e8a0 fa20230 9198199 f0f9c29 2554770 f0f9c29 fa20230 f0f9c29 fa20230 f0f9c29 fa20230 f0f9c29 2554770 270b39e 9198199 47d42b8 794a732 |
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 |
import streamlit as st
import tensorflow as tf
import numpy as np
from PIL import Image
import cv2
labels = ["Column","Header","Table"]
threshold = 0.75
model = tf.saved_model.load("best_saved_model") #Loading the saved model
def process_img(img):
img = img.resize((640,640)) # resize the image as reqired for the model input
img = np.array(img) # Convert Pil Object into numpy array
copy_img = img.copy() # Save a copy for backup
img = img/255 # Normalizing the pixel value
img = img.astype("float32") # Convert the format double to format float
img = np.expand_dims(img,axis=0) # exapanding dimension to add batch
return img,copy_img
st.title("Table ExtractV2")
file_name = st.file_uploader("Upload a report image")
if file_name is not None:
col1, col2 = st.columns(2)
col3, col4 = st.columns(2)
image = Image.open(file_name)
input_image, copy_img= process_img(image)
col1.header("Input Image")
col1.image(input_image, use_column_width=True)
bbox,confidance,classes,nc = model(input_image)
bbox,confidance , classes , nc = bbox[0].numpy(),confidance[0].numpy(),classes[0].numpy(),nc[0].numpy()
col3.subheader("Detected Result")
table_count =0
header_count = 0
column_count = 0
for i in range(nc):
if confidance[i] >= threshold:
x1,y1,x2,y2 = bbox[i]*640
class_name = labels[int(classes[i])]
col3.text(class_name+" : "+str(int(confidance[i]*100))+"%")
if class_name =="Header":
header_count+=1
color = (0,0,255) #Blue color
cv2.rectangle(copy_img, (int(x1), int(y1)), (int(x2), int(y2)),color, 2)
if class_name =="Column":
column_count+=1
color = (0,255,0) #Green color
cv2.rectangle(copy_img, (int(x1), int(y1)), (int(x2), int(y2)),color, 2)
if class_name =="Table":
table_count+=1
color = (255,0,0) #Red color
cv2.rectangle(copy_img, (int(x1), int(y1)), (int(x2), int(y2)),color, 2)
col4.text("No of Table Detected : "+str(table_count))
col4.text("No of Header Detected : "+str(header_count))
col4.text("No of Column Detected : "+str(column_count))
col2.header("Output Result")
col2.image(copy_img, use_column_width=True)
|