ITSAIDI commited on
Commit
7c48137
1 Parent(s): 08d827a
Files changed (1) hide show
  1. utilitis.py +37 -3
utilitis.py CHANGED
@@ -1,6 +1,6 @@
1
  import streamlit as st
2
  from paddleocr import PaddleOCR
3
- from PIL import ImageDraw, ImageFont
4
  import torch
5
  from transformers import AutoProcessor,LayoutLMv3ForTokenClassification
6
  import numpy as np
@@ -113,6 +113,7 @@ def Get_Json(true_predictions,words):
113
  #############################################################################
114
  #############################################################################
115
  def Draw(image):
 
116
  true_predictions, true_boxes,words = Run_model(image)
117
  draw = ImageDraw.Draw(image)
118
 
@@ -210,7 +211,7 @@ def Change_Image(image1,image2):
210
  st.session_state.current_image = 'image1'
211
 
212
  # Button to switch between images
213
- if st.sidebar.button('Remove'):
214
  if st.session_state.current_image == 'image1':
215
  st.session_state.current_image = 'image2'
216
  else:
@@ -219,4 +220,37 @@ def Change_Image(image1,image2):
219
  if st.session_state.current_image == 'image1':
220
  st.image(image1, caption='Output', use_column_width=True)
221
  else:
222
- st.image(image2, caption='Image initiale', use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from paddleocr import PaddleOCR
3
+ from PIL import ImageDraw, ImageFont,ImageEnhance
4
  import torch
5
  from transformers import AutoProcessor,LayoutLMv3ForTokenClassification
6
  import numpy as np
 
113
  #############################################################################
114
  #############################################################################
115
  def Draw(image):
116
+ image = enhance_image(image,1.3,1.5)
117
  true_predictions, true_boxes,words = Run_model(image)
118
  draw = ImageDraw.Draw(image)
119
 
 
211
  st.session_state.current_image = 'image1'
212
 
213
  # Button to switch between images
214
+ if st.sidebar.button('Switcher'):
215
  if st.session_state.current_image == 'image1':
216
  st.session_state.current_image = 'image2'
217
  else:
 
220
  if st.session_state.current_image == 'image1':
221
  st.image(image1, caption='Output', use_column_width=True)
222
  else:
223
+ st.image(image2, caption='Image initiale', use_column_width=True)
224
+
225
+ #############################################################################
226
+ #############################################################################
227
+ def enhance_image(image,brightness_factor, contrast_factor):
228
+ enhancer = ImageEnhance.Brightness(image)
229
+ brightened_image = enhancer.enhance(brightness_factor)
230
+ enhancer = ImageEnhance.Contrast(brightened_image)
231
+ enhanced_image = enhancer.enhance(contrast_factor)
232
+ return enhanced_image
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+