resolved bug of dataframe
Browse files
app.py
CHANGED
@@ -72,7 +72,7 @@ if data:
|
|
72 |
# Apply OCR and NER
|
73 |
file_name = ocr(img_name)
|
74 |
Output_dict = ner(file_name)
|
75 |
-
df = pd.DataFrame(Output_dict)
|
76 |
|
77 |
ocr_data = ""
|
78 |
with open(os.path.join('runs', 'segment', path['MAIN_FLOW_INFERENCE_FOLDER'], 'ocr_label_data', data.name.split('.')[0]+'.txt'),'r+') as f :
|
@@ -81,6 +81,75 @@ if data:
|
|
81 |
st.text(ocr_data)
|
82 |
|
83 |
st.header("NER Output")
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
# Apply OCR and NER
|
73 |
file_name = ocr(img_name)
|
74 |
Output_dict = ner(file_name)
|
75 |
+
# df = pd.DataFrame(Output_dict)
|
76 |
|
77 |
ocr_data = ""
|
78 |
with open(os.path.join('runs', 'segment', path['MAIN_FLOW_INFERENCE_FOLDER'], 'ocr_label_data', data.name.split('.')[0]+'.txt'),'r+') as f :
|
|
|
81 |
st.text(ocr_data)
|
82 |
|
83 |
st.header("NER Output")
|
84 |
+
|
85 |
+
new_df = pd.DataFrame()
|
86 |
+
new_df['Entity'] = list(Output_dict.keys())
|
87 |
+
|
88 |
+
# print(df)
|
89 |
+
new_df['Value'] = list(Output_dict.values())
|
90 |
+
new_df['Value'] = new_df['Value'].astype('str')
|
91 |
+
st.table(new_df)
|
92 |
+
|
93 |
+
else:
|
94 |
+
img_name = '3.jpg'
|
95 |
+
img = cv2.imread(img_name,0)
|
96 |
+
|
97 |
+
if img.shape[0] > 1500:
|
98 |
+
height, width = img.shape
|
99 |
+
img = img[height//4:-height//4, width//4:-width//4]
|
100 |
+
|
101 |
+
cv2.imwrite(os.path.join('grey_images',img_name), img)
|
102 |
+
|
103 |
+
#call main function
|
104 |
+
# main(os.path.join('grey_images',img_name))
|
105 |
+
file_path = os.path.join('grey_images',img_name)
|
106 |
+
img_name = os.path.basename(file_path)
|
107 |
+
|
108 |
+
|
109 |
+
col1,col2 = st.columns(2)
|
110 |
+
|
111 |
+
with col1:
|
112 |
+
st.markdown("<h3 style='text-align: center;'>Grey Image</h1>", unsafe_allow_html=True)
|
113 |
+
st.image(os.path.join('grey_images',img_name))
|
114 |
+
|
115 |
+
# Object detection and enhance image
|
116 |
+
seg_result, img_file = object_detection(file_path)
|
117 |
+
croped_img = crop_image(seg_result, img_file, img_name)
|
118 |
+
image = enhance_image(croped_img, img_name)
|
119 |
+
|
120 |
+
st.markdown("<h3 style='text-align: center;'>Enhanced Image</h1>", unsafe_allow_html=True)
|
121 |
+
st.image(os.path.join('runs', 'segment', path['MAIN_FLOW_INFERENCE_FOLDER'], 'enhanced', img_name))
|
122 |
+
|
123 |
+
|
124 |
+
with col2:
|
125 |
+
st.markdown("<h3 style='text-align: center;'>Detected Image</h1>", unsafe_allow_html=True)
|
126 |
+
st.image(os.path.join('runs', 'segment',path['MAIN_FLOW_INFERENCE_FOLDER'],img_name))
|
127 |
+
|
128 |
+
# Rotation
|
129 |
+
processed_img = morphological_transform(image)
|
130 |
+
rotated_image, image = hoffman_transform(processed_img, image)
|
131 |
+
img_name = pytesseract_rotate(rotated_image, image, img_name)
|
132 |
+
|
133 |
+
st.markdown("<h3 style='text-align: center;'>Rotated Image</h1>", unsafe_allow_html=True)
|
134 |
+
st.image(os.path.join('runs', 'segment', path['MAIN_FLOW_INFERENCE_FOLDER'], 'rotated_image', img_name))
|
135 |
+
|
136 |
+
# Apply OCR and NER
|
137 |
+
file_name = ocr(img_name)
|
138 |
+
Output_dict = ner(file_name)
|
139 |
+
# df = pd.DataFrame(Output_dict)
|
140 |
+
|
141 |
+
ocr_data = ""
|
142 |
+
with open(os.path.join('runs', 'segment', path['MAIN_FLOW_INFERENCE_FOLDER'], 'ocr_label_data', img_name.split('.')[0]+'.txt'),'r+') as f :
|
143 |
+
ocr_data = f.read()
|
144 |
+
st.header("OCR Text Output")
|
145 |
+
st.text(ocr_data)
|
146 |
+
|
147 |
+
st.header("NER Output")
|
148 |
+
|
149 |
+
new_df = pd.DataFrame()
|
150 |
+
new_df['Entity'] = list(Output_dict.keys())
|
151 |
+
|
152 |
+
# print(df)
|
153 |
+
new_df['Value'] = list(Output_dict.values())
|
154 |
+
new_df['Value'] = new_df['Value'].astype('str')
|
155 |
+
st.table(new_df)
|