BilalHasan commited on
Commit
19c3065
·
verified ·
1 Parent(s): 4310234

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -10
app.py CHANGED
@@ -16,7 +16,6 @@ def preprocess_image(image):
16
  bin_image = cv.copyMakeBorder(bin_image, int(0.10 * image.shape[0]), int(0.05 * image.shape[0]), int(0.05 * image.shape[1]), int(0.10 * image.shape[1]), cv.BORDER_CONSTANT, value=(255, 255, 255))
17
  return bin_image
18
 
19
- #bin_image = preprocess_image(image)
20
 
21
  def split_image_into_lines(image):
22
  lines = []
@@ -52,7 +51,6 @@ def split_image_into_lines(image):
52
 
53
  return lines
54
 
55
- #lines = split_image_into_lines(bin_image)
56
 
57
 
58
  def generate_text(line):
@@ -119,24 +117,19 @@ max_width = 0.9
119
  out_image_width = 1500
120
  top_margin = 100
121
 
122
- #out_image = put_text(improved_text, font, font_scale, color, thickness, max_width, out_image_width, top_margin)
123
 
124
  def predict(input_path):
125
  image = cv.imread(input_path)
126
  bin_image = preprocess_image(image)
127
- print("Preprocessing Complete!")
128
  lines = split_image_into_lines(bin_image)
129
- print("Splitting complete!")
130
  improved_text = get_improved_result(lines)
131
- print("Improvement done!")
132
  out_image = put_text(improved_text, font, font_scale, color, thickness, max_width, out_image_width, top_margin)
133
- print("Out image generated!")
134
- return out_image
135
 
136
  gradio_app = gr.Interface(
137
  predict,
138
- inputs=gr.Image(label= '', sources=['upload', 'webcam'], type='filepath'),
139
- outputs=[gr.Image(label= '')],
140
  title="Extract Handwritten Text",
141
  )
142
 
 
16
  bin_image = cv.copyMakeBorder(bin_image, int(0.10 * image.shape[0]), int(0.05 * image.shape[0]), int(0.05 * image.shape[1]), int(0.10 * image.shape[1]), cv.BORDER_CONSTANT, value=(255, 255, 255))
17
  return bin_image
18
 
 
19
 
20
  def split_image_into_lines(image):
21
  lines = []
 
51
 
52
  return lines
53
 
 
54
 
55
 
56
  def generate_text(line):
 
117
  out_image_width = 1500
118
  top_margin = 100
119
 
 
120
 
121
  def predict(input_path):
122
  image = cv.imread(input_path)
123
  bin_image = preprocess_image(image)
 
124
  lines = split_image_into_lines(bin_image)
 
125
  improved_text = get_improved_result(lines)
 
126
  out_image = put_text(improved_text, font, font_scale, color, thickness, max_width, out_image_width, top_margin)
127
+ return out_image, improved_text
 
128
 
129
  gradio_app = gr.Interface(
130
  predict,
131
+ inputs=gr.Image(sources=['upload', 'webcam'], type='filepath'),
132
+ outputs=[gr.Image(), gradio.Textbox()],
133
  title="Extract Handwritten Text",
134
  )
135