Spaces:
Sleeping
Sleeping
fix: process pdf once
Browse files
app.py
CHANGED
@@ -143,7 +143,8 @@ with gr.Blocks() as demo:
|
|
143 |
|
144 |
with gr.Row():
|
145 |
with gr.Column(scale=1):
|
146 |
-
selected_image = gr.
|
|
|
147 |
got_mode = gr.Dropdown(
|
148 |
choices=[
|
149 |
"plain texts OCR",
|
@@ -163,10 +164,11 @@ with gr.Blocks() as demo:
|
|
163 |
with gr.Column(scale=2):
|
164 |
ocr_output = gr.HTML(label="识别结果")
|
165 |
|
166 |
-
def select_image(evt: gr.SelectData):
|
167 |
-
|
|
|
168 |
|
169 |
-
image_gallery.select(select_image,
|
170 |
convert_button.click(convert_pdf_to_images, inputs=[pdf_input], outputs=[gr.Textbox(visible=False), image_gallery])
|
171 |
ocr_button.click(ocr_process, inputs=[selected_image, got_mode, ocr_color, ocr_box], outputs=ocr_output)
|
172 |
|
|
|
143 |
|
144 |
with gr.Row():
|
145 |
with gr.Column(scale=1):
|
146 |
+
selected_image = gr.State(value=None) # 使用 gr.State 来存储选中的图片路径
|
147 |
+
preview_image = gr.Image(label="选中的图片", type="filepath")
|
148 |
got_mode = gr.Dropdown(
|
149 |
choices=[
|
150 |
"plain texts OCR",
|
|
|
164 |
with gr.Column(scale=2):
|
165 |
ocr_output = gr.HTML(label="识别结果")
|
166 |
|
167 |
+
def select_image(evt: gr.SelectData, gallery):
|
168 |
+
selected = gallery[evt.index]
|
169 |
+
return selected, selected
|
170 |
|
171 |
+
image_gallery.select(select_image, image_gallery, [selected_image, preview_image])
|
172 |
convert_button.click(convert_pdf_to_images, inputs=[pdf_input], outputs=[gr.Textbox(visible=False), image_gallery])
|
173 |
ocr_button.click(ocr_process, inputs=[selected_image, got_mode, ocr_color, ocr_box], outputs=ocr_output)
|
174 |
|