Mageia commited on
Commit
6d6872c
·
unverified ·
1 Parent(s): 70b6f98

fix: got_ocr

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -71,18 +71,25 @@ def on_image_select(evt: gr.SelectData):
71
 
72
 
73
  # 更新perform_ocr函数的输入参数
74
- def perform_ocr(selected_index, image_gallery, task, fine_grained_type, color, box):
75
  if selected_index is None or len(image_gallery) == 0:
76
  return "请先选择一张图片"
77
 
78
  selected_image = image_gallery[selected_index][0]
79
 
80
  # 根据选择的任务和参数调用GOT OCR
81
- got_mode = task
82
  ocr_color = color if fine_grained_type == "color" else ""
83
  ocr_box = box if fine_grained_type == "box" else ""
84
 
85
- result, _ = got_ocr(model, tokenizer, selected_image, got_mode=got_mode, fine_grained_mode=fine_grained_type, ocr_color=ocr_color, ocr_box=ocr_box)
 
 
 
 
 
 
 
 
86
  return result
87
 
88
 
@@ -106,6 +113,10 @@ with gr.Blocks() as demo:
106
  pdf_input = gr.File(label="上传PDF文件")
107
  image_gallery = gr.Gallery(label="PDF页面预览", columns=3, height="auto")
108
  selected_index = gr.State(None)
 
 
 
 
109
  task_dropdown = gr.Dropdown(
110
  choices=["plain texts OCR", "format texts OCR", "plain multi-crop OCR", "format multi-crop OCR", "plain fine-grained OCR", "format fine-grained OCR"],
111
  label="选择GOT模式",
@@ -123,14 +134,11 @@ with gr.Blocks() as demo:
123
 
124
  # 更新ocr_button的click事件,传递所有必要的参数
125
  ocr_button.click(
126
- fn=perform_ocr, inputs=[selected_index, image_gallery, task_dropdown, fine_grained_dropdown, color_dropdown, box_input], outputs=ocr_result
 
 
127
  )
128
 
129
- pdf_input.upload(fn=process_pdf, inputs=pdf_input, outputs=image_gallery)
130
- image_gallery.select(fn=on_image_select, inputs=[], outputs=selected_index)
131
- ocr_button.click(fn=perform_ocr, inputs=[selected_index, image_gallery], outputs=ocr_result)
132
-
133
- # 移除了选中图片的显示部分
134
 
135
  if __name__ == "__main__":
136
  demo.launch()
 
71
 
72
 
73
  # 更新perform_ocr函数的输入参数
74
+ def perform_ocr(selected_index, image_gallery, got_mode, fine_grained_type, color, box):
75
  if selected_index is None or len(image_gallery) == 0:
76
  return "请先选择一张图片"
77
 
78
  selected_image = image_gallery[selected_index][0]
79
 
80
  # 根据选择的任务和参数调用GOT OCR
 
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,
88
+ got_mode=got_mode,
89
+ fine_grained_mode=fine_grained_type,
90
+ ocr_color=ocr_color,
91
+ ocr_box=ocr_box,
92
+ )
93
  return result
94
 
95
 
 
113
  pdf_input = gr.File(label="上传PDF文件")
114
  image_gallery = gr.Gallery(label="PDF页面预览", columns=3, height="auto")
115
  selected_index = gr.State(None)
116
+ pdf_input.upload(fn=process_pdf, inputs=pdf_input, outputs=image_gallery)
117
+ image_gallery.select(fn=on_image_select, inputs=[], outputs=selected_index)
118
+
119
+ ####################
120
  task_dropdown = gr.Dropdown(
121
  choices=["plain texts OCR", "format texts OCR", "plain multi-crop OCR", "format multi-crop OCR", "plain fine-grained OCR", "format fine-grained OCR"],
122
  label="选择GOT模式",
 
134
 
135
  # 更新ocr_button的click事件,传递所有必要的参数
136
  ocr_button.click(
137
+ fn=perform_ocr,
138
+ inputs=[selected_index, image_gallery, task_dropdown, fine_grained_dropdown, color_dropdown, box_input],
139
+ outputs=ocr_result,
140
  )
141
 
 
 
 
 
 
142
 
143
  if __name__ == "__main__":
144
  demo.launch()