905saini commited on
Commit
9198199
·
1 Parent(s): 47d42b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -2,6 +2,9 @@ import streamlit as st
2
  import tensorflow as tf
3
  from PIL import Image
4
  import cv2
 
 
 
5
  model = tf.saved_model.load("best_saved_model") #Loading the saved model
6
 
7
  def process_img(img_path):
@@ -22,6 +25,27 @@ if file_name is not None:
22
 
23
  input_image,copy_image = process_img(file_name)
24
  col1.image(input_image, use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
 
27
 
 
2
  import tensorflow as tf
3
  from PIL import Image
4
  import cv2
5
+
6
+ labels = ["Column","Header","Table"]
7
+ threshold = 0.75
8
  model = tf.saved_model.load("best_saved_model") #Loading the saved model
9
 
10
  def process_img(img_path):
 
25
 
26
  input_image,copy_image = process_img(file_name)
27
  col1.image(input_image, use_column_width=True)
28
+
29
+ bbox,confidance,classes,nc = model(input_img)
30
+ bbox,confidance , classes , nc = bbox[0].numpy(),confidance[0].numpy(),classes[0].numpy(),nc[0].numpy()
31
+
32
+ for i in range(nc):
33
+ if confidance[i] >= threshold:
34
+ x1,y1,x2,y2 = bbox[i]*640
35
+ class_name = labels[int(classes[i])]
36
+ if class_name =="Header":
37
+ color = (0,0,255) #Blue color
38
+ cv2.rectangle(copy_img, (int(x1), int(y1)), (int(x2), int(y2)),color, 2)
39
+
40
+ if class_name =="Column":
41
+ color = (0,255,0) #Green color
42
+ cv2.rectangle(copy_img, (int(x1), int(y1)), (int(x2), int(y2)),color, 2)
43
+
44
+ if class_name =="Table":
45
+ color = (255,0,0) #Red color
46
+ cv2.rectangle(copy_img, (int(x1), int(y1)), (int(x2), int(y2)),color, 2)
47
+
48
+ col2.image(copy_img, use_column_width=True)
49
 
50
 
51