groueix commited on
Commit
d51cc1f
·
1 Parent(s): 255a121

added write to RAM if available

Browse files
Files changed (3) hide show
  1. README.md +4 -7
  2. copaint/copaint.py +4 -0
  3. copaint/gradio_ui.py +8 -3
README.md CHANGED
@@ -49,12 +49,9 @@ poetry build
49
  poetry publish
50
  ```
51
 
52
- ## Todo
53
- -- Preload copaint logo ()
54
- ```
55
- Loaded image of shape torch.Size([1, 4, 1848, 1844]), from copaint/static/logo_copaint.png
56
- Image to tensor conversion took 0.0459 seconds
57
- ```
58
- -- Same for insta logo
59
 
60
 
 
 
49
  poetry publish
50
  ```
51
 
52
+ ## Time bottleneck
53
+ -- the biggest time bottleneck is writing to disk the back image and loading for the PDF creation.
54
+
 
 
 
 
55
 
56
 
57
+ # Deploy to huggingface.
copaint/copaint.py CHANGED
@@ -209,6 +209,10 @@ def save_tensor_to_pdf(tensor, pdf_path, is_front=True, margin=0.25, img_small_s
209
  t3 = time.time()
210
  # Use PNG for high-res mode instead of JPG
211
  image_path = "temp.png" if high_res else "temp.jpg"
 
 
 
 
212
  image.save(image_path)
213
  if debug:
214
  logger.debug(f"Temporary image saving took {time.time() - t3:.4f} seconds")
 
209
  t3 = time.time()
210
  # Use PNG for high-res mode instead of JPG
211
  image_path = "temp.png" if high_res else "temp.jpg"
212
+ ram_folder_linux = "/dev/shm/"
213
+ if os.path.exists(ram_folder_linux):
214
+ image_path = os.path.join(ram_folder_linux, image_path)
215
+
216
  image.save(image_path)
217
  if debug:
218
  logger.debug(f"Temporary image saving took {time.time() - t3:.4f} seconds")
copaint/gradio_ui.py CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
4
  import shutil
5
  import tempfile
6
  import logging
7
-
8
  from gradio_pdf import PDF
9
  from importlib.resources import files
10
  from pathlib import Path
@@ -112,8 +112,13 @@ def process_copaint(
112
  ):
113
  """Process the input and generate CopainT PDF"""
114
  # Create temporary directories for processing
115
- temp_input_dir = tempfile.mkdtemp()
116
- temp_output_dir = tempfile.mkdtemp()
 
 
 
 
 
117
 
118
  try:
119
  # Save uploaded images to temp directory
 
4
  import shutil
5
  import tempfile
6
  import logging
7
+ import os
8
  from gradio_pdf import PDF
9
  from importlib.resources import files
10
  from pathlib import Path
 
112
  ):
113
  """Process the input and generate CopainT PDF"""
114
  # Create temporary directories for processing
115
+ # Use /dev/shm if available for better performance
116
+ if os.path.exists('/dev/shm'):
117
+ temp_input_dir = tempfile.mkdtemp(dir='/dev/shm')
118
+ temp_output_dir = tempfile.mkdtemp(dir='/dev/shm')
119
+ else:
120
+ temp_input_dir = tempfile.mkdtemp()
121
+ temp_output_dir = tempfile.mkdtemp()
122
 
123
  try:
124
  # Save uploaded images to temp directory