merterbak commited on
Commit
ac0d443
·
verified ·
1 Parent(s): cf3c6a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -197,6 +197,11 @@ def toggle_prompt(task):
197
  return gr.update(visible=True, label="Text to Locate", placeholder="Enter text")
198
  return gr.update(visible=False)
199
 
 
 
 
 
 
200
  def get_pdf_page_count(file_path):
201
  if not file_path or not file_path.lower().endswith('.pdf'):
202
  return 1
@@ -247,16 +252,16 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek-OCR") as demo:
247
  btn = gr.Button("Extract", variant="primary", size="lg")
248
 
249
  with gr.Column(scale=2):
250
- with gr.Tabs():
251
- with gr.Tab("Text"):
252
  text_out = gr.Textbox(lines=20, show_copy_button=True, show_label=False)
253
- with gr.Tab("Markdown"):
254
  md_out = gr.Markdown("")
255
- with gr.Tab("Boxes"):
256
  img_out = gr.Image(type="pil", height=500, show_label=False)
257
- with gr.Tab("Cropped Images"):
258
  gallery = gr.Gallery(show_label=False, columns=3, height=400)
259
- with gr.Tab("Raw Text"):
260
  raw_out = gr.Textbox(lines=20, show_copy_button=True, show_label=False)
261
 
262
  gr.Examples(
@@ -289,6 +294,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek-OCR") as demo:
289
  file_in.change(update_page_selector, [file_in], [page_selector])
290
  page_selector.change(load_image, [file_in, page_selector], [input_img])
291
  task.change(toggle_prompt, [task], [prompt])
 
292
 
293
  def run(image, file_path, mode, task, custom_prompt, page_num):
294
  if file_path:
@@ -297,8 +303,9 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek-OCR") as demo:
297
  return process_image(image, mode, task, custom_prompt)
298
  return "Error uploading file or image", "", "", None, []
299
 
300
- btn.click(run, [input_img, file_in, mode, task, prompt, page_selector],
301
- [text_out, md_out, raw_out, img_out, gallery])
 
302
 
303
  if __name__ == "__main__":
304
  demo.queue(max_size=20).launch()
 
197
  return gr.update(visible=True, label="Text to Locate", placeholder="Enter text")
198
  return gr.update(visible=False)
199
 
200
+ def select_boxes(task):
201
+ if task == "📍 Locate":
202
+ return gr.update(selected="tab_boxes")
203
+ return gr.update()
204
+
205
  def get_pdf_page_count(file_path):
206
  if not file_path or not file_path.lower().endswith('.pdf'):
207
  return 1
 
252
  btn = gr.Button("Extract", variant="primary", size="lg")
253
 
254
  with gr.Column(scale=2):
255
+ with gr.Tabs() as tabs:
256
+ with gr.Tab("Text", id="tab_text"):
257
  text_out = gr.Textbox(lines=20, show_copy_button=True, show_label=False)
258
+ with gr.Tab("Markdown Preview", id="tab_markdown"):
259
  md_out = gr.Markdown("")
260
+ with gr.Tab("Boxes", id="tab_boxes"):
261
  img_out = gr.Image(type="pil", height=500, show_label=False)
262
+ with gr.Tab("Cropped Images", id="tab_crops"):
263
  gallery = gr.Gallery(show_label=False, columns=3, height=400)
264
+ with gr.Tab("Raw Text", id="tab_raw"):
265
  raw_out = gr.Textbox(lines=20, show_copy_button=True, show_label=False)
266
 
267
  gr.Examples(
 
294
  file_in.change(update_page_selector, [file_in], [page_selector])
295
  page_selector.change(load_image, [file_in, page_selector], [input_img])
296
  task.change(toggle_prompt, [task], [prompt])
297
+ task.change(select_boxes, [task], [tabs])
298
 
299
  def run(image, file_path, mode, task, custom_prompt, page_num):
300
  if file_path:
 
303
  return process_image(image, mode, task, custom_prompt)
304
  return "Error uploading file or image", "", "", None, []
305
 
306
+ submit_event = btn.click(run, [input_img, file_in, mode, task, prompt, page_selector],
307
+ [text_out, md_out, raw_out, img_out, gallery])
308
+ submit_event.then(select_boxes, [task], [tabs])
309
 
310
  if __name__ == "__main__":
311
  demo.queue(max_size=20).launch()