Mageia commited on
Commit
61f1538
1 Parent(s): 6d6872c

fix: got_ocr

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -33,7 +33,7 @@ def pdf_to_images(pdf_path):
33
  pix = page.get_pixmap(matrix=mat, alpha=False)
34
  img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
35
 
36
- # 增加对比度
37
  enhancer = ImageEnhance.Contrast(img)
38
  img = enhancer.enhance(1.5) # 增加50%的对比度
39
 
@@ -81,7 +81,7 @@ def perform_ocr(selected_index, image_gallery, got_mode, fine_grained_type, colo
81
  ocr_color = color if fine_grained_type == "color" else ""
82
  ocr_box = box if fine_grained_type == "box" else ""
83
 
84
- result, _ = got_ocr(
85
  model,
86
  tokenizer,
87
  selected_image,
@@ -90,7 +90,11 @@ def perform_ocr(selected_index, image_gallery, got_mode, fine_grained_type, colo
90
  ocr_color=ocr_color,
91
  ocr_box=ocr_box,
92
  )
93
- return result
 
 
 
 
94
 
95
 
96
  def task_update(task):
@@ -127,7 +131,7 @@ with gr.Blocks() as demo:
127
  box_input = gr.Textbox(label="输入框: [x1,y1,x2,y2]", placeholder="例如: [0,0,100,100]", visible=False)
128
 
129
  ocr_button = gr.Button("开始OCR识别")
130
- ocr_result = gr.Textbox(label="OCR结果")
131
 
132
  task_dropdown.change(task_update, inputs=[task_dropdown], outputs=[fine_grained_dropdown, color_dropdown, box_input])
133
  fine_grained_dropdown.change(fine_grained_update, inputs=[fine_grained_dropdown], outputs=[color_dropdown, box_input])
 
33
  pix = page.get_pixmap(matrix=mat, alpha=False)
34
  img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
35
 
36
+ # 增��对比度
37
  enhancer = ImageEnhance.Contrast(img)
38
  img = enhancer.enhance(1.5) # 增加50%的对比度
39
 
 
81
  ocr_color = color if fine_grained_type == "color" else ""
82
  ocr_box = box if fine_grained_type == "box" else ""
83
 
84
+ result, html_content = got_ocr(
85
  model,
86
  tokenizer,
87
  selected_image,
 
90
  ocr_color=ocr_color,
91
  ocr_box=ocr_box,
92
  )
93
+
94
+ if html_content:
95
+ return gr.HTML(f'<iframe srcdoc="{html_content}" width="100%" height="600px"></iframe>')
96
+ else:
97
+ return result
98
 
99
 
100
  def task_update(task):
 
131
  box_input = gr.Textbox(label="输入框: [x1,y1,x2,y2]", placeholder="例如: [0,0,100,100]", visible=False)
132
 
133
  ocr_button = gr.Button("开始OCR识别")
134
+ ocr_result = gr.HTML(label="OCR结果") # 将Textbox更改为HTML组件
135
 
136
  task_dropdown.change(task_update, inputs=[task_dropdown], outputs=[fine_grained_dropdown, color_dropdown, box_input])
137
  fine_grained_dropdown.change(fine_grained_update, inputs=[fine_grained_dropdown], outputs=[color_dropdown, box_input])