zliang commited on
Commit
0bd2433
·
verified ·
1 Parent(s): 4504622

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -30,6 +30,11 @@ def crop_images_from_boxes(image, boxes, scale_factor):
30
  ]
31
  return cropped_images
32
 
 
 
 
 
 
33
  @spaces.GPU
34
  def process_pdf(pdf_file):
35
  # Open the PDF file
@@ -45,7 +50,7 @@ def process_pdf(pdf_file):
45
 
46
  # Pre-cache all page pixmaps at low DPI
47
  low_res_pixmaps = [page.get_pixmap(dpi=low_dpi) for page in doc]
48
-
49
  # Loop through each page
50
  for page_num, low_res_pix in enumerate(low_res_pixmaps):
51
  low_res_img = np.frombuffer(low_res_pix.samples, dtype=np.uint8).reshape(low_res_pix.height, low_res_pix.width, 3)
@@ -64,6 +69,9 @@ def process_pdf(pdf_file):
64
 
65
  return all_cropped_images
66
 
 
 
 
67
  # Create Gradio interface
68
  iface = gr.Interface(
69
  fn=process_pdf,
 
30
  ]
31
  return cropped_images
32
 
33
+ # Warm-up function to perform a dummy inference
34
+ def warm_up_model():
35
+ dummy_image = np.zeros((640, 512, 3), dtype=np.uint8)
36
+ infer_image_and_get_boxes(dummy_image)
37
+
38
  @spaces.GPU
39
  def process_pdf(pdf_file):
40
  # Open the PDF file
 
50
 
51
  # Pre-cache all page pixmaps at low DPI
52
  low_res_pixmaps = [page.get_pixmap(dpi=low_dpi) for page in doc]
53
+
54
  # Loop through each page
55
  for page_num, low_res_pix in enumerate(low_res_pixmaps):
56
  low_res_img = np.frombuffer(low_res_pix.samples, dtype=np.uint8).reshape(low_res_pix.height, low_res_pix.width, 3)
 
69
 
70
  return all_cropped_images
71
 
72
+ # Warm-up the model before launching the app
73
+ warm_up_model()
74
+
75
  # Create Gradio interface
76
  iface = gr.Interface(
77
  fn=process_pdf,