Spaces:
Sleeping
Sleeping
baseline08_beta0.3.9.1_03Oct25: fixing slow Marker: @spaces.GPU moved to convert_files starting at 180s
Browse filesFiles changed (3)
5 unmodified lines678910119 unmodified lines2122232425262787 unmodified lines1151161171181191201214 unmodified lines12612712812913013113245 unmodified lines1781791801811821835 unmodified linesimport timeimport spacesfrom converters.extraction_converter import DocumentConverter #, DocumentExtractor #as docextractor #ExtractionConverter #get_extraction_converter ## SMY: should disusefrom file_handler.file_utils import write_markdown, dump_images, collect_pdf_paths, collect_html_paths, collect_markdown_paths, create_outputdir9 unmodified linesconverter = None #DocumentConverter#converter:DocumentConverter.converter = None@spaces.GPU# Define docextractor in the pool as serialised object and passed to each worker process.# Note: DocumentConverter must be "picklable".def init_worker(#self,87 unmodified lines#duration = 5.75 * pdf_files_count if pdf_files_count>=2 else 7#duration = 10#@spaces.GPU(duration=duration) ## HF Spaces GPU support@spaces.GPU## moved from extraction_converter ( to standalone extract_to_md)#def extract(self, src_path: str, output_dir: str) -> Dict[str, int, Union[str, Path]]:def extract(self, src_path: str, output_dir: str): #Dict:4 unmodified linesReturns a dict with metadata, e.g. {"filename": <file.name>, "images": <count>, "filepath": <filepath>}."""from globals import config_load_modelstry:## SMY: TODO: convert htmls to PDF. Marker will by default attempt weasyprint which typically raise 'libgobject-2' error on Winweasyprint_libpath = config_load_models.weasyprint_libpath if config_load_models.weasyprint_libpath else None45 unmodified lines#return {"images": len(rendered.images), "file": md_file} ##debugreturn {"file": md_file.name, "images": images_count, "filepath": md_file, "image_path": image_path} ####SMY should be Dict[str, int, str]. Dicts are not necessarily ordered.#def convert_files(src_path: str, output_dir: str, max_retries: int = 2) -> str:#def convert_files(self, src_path: str, output_dir_string: str = None, max_retries: int = 2, progress = gr.Progress()) -> Union[Dict, str]: #str:def convert_files(self, src_path: str, max_retries: int = 2) -> Union[Dict, str]:5 unmodified lines67891011129 unmodified lines2223242526272887 unmodified lines1161171181191201211224 unmodified lines12712812913013113213345 unmodified lines1791801811821831841851861875 unmodified linesimport timeimport spacesfrom globals import config_load_modelsfrom converters.extraction_converter import DocumentConverter #, DocumentExtractor #as docextractor #ExtractionConverter #get_extraction_converter ## SMY: should disusefrom file_handler.file_utils import write_markdown, dump_images, collect_pdf_paths, collect_html_paths, collect_markdown_paths, create_outputdir9 unmodified linesconverter = None #DocumentConverter#converter:DocumentConverter.converter = None#@spaces.GPU# Define docextractor in the pool as serialised object and passed to each worker process.# Note: DocumentConverter must be "picklable".def init_worker(#self,87 unmodified lines#duration = 5.75 * pdf_files_count if pdf_files_count>=2 else 7#duration = 10#@spaces.GPU(duration=duration) ## HF Spaces GPU support#@spaces.GPU## moved from extraction_converter ( to standalone extract_to_md)#def extract(self, src_path: str, output_dir: str) -> Dict[str, int, Union[str, Path]]:def extract(self, src_path: str, output_dir: str): #Dict:4 unmodified linesReturns a dict with metadata, e.g. {"filename": <file.name>, "images": <count>, "filepath": <filepath>}."""#from globals import config_load_models ##SMY: moved to top-level importtry:## SMY: TODO: convert htmls to PDF. Marker will by default attempt weasyprint which typically raise 'libgobject-2' error on Winweasyprint_libpath = config_load_models.weasyprint_libpath if config_load_models.weasyprint_libpath else None45 unmodified lines#return {"images": len(rendered.images), "file": md_file} ##debugreturn {"file": md_file.name, "images": images_count, "filepath": md_file, "image_path": image_path} ####SMY should be Dict[str, int, str]. Dicts are not necessarily ordered.#duration = 5.75 * pdf_files_count if pdf_files_count>=2 else 7duration = 20*config_load_models.pdf_files_count if config_load_models.pdf_files_count>=10 else 180 ## sec@spaces.GPU(duration=duration) ## HF Spaces GPU support#def convert_files(src_path: str, output_dir: str, max_retries: int = 2) -> str:#def convert_files(self, src_path: str, output_dir_string: str = None, max_retries: int = 2, progress = gr.Progress()) -> Union[Dict, str]: #str:def convert_files(self, src_path: str, max_retries: int = 2) -> Union[Dict, str]:
7 unmodified lines89101112137 unmodified linesself.model_dict = {}self.weasyprint_libpath = ""self.config_ini = "utils\\config.ini"# Create a single, shared instance of the Config class# Other modules will import and use this instance.7 unmodified lines8910111213147 unmodified linesself.model_dict = {}self.weasyprint_libpath = ""self.config_ini = "utils\\config.ini"self.pdf_files_count = 0# Create a single, shared instance of the Config class# Other modules will import and use this instance.
160 unmodified lines161162163164165166160 unmodified linespage_range = page_range if page_range else get_config_value(config_file,"MARKER_CAP", "PAGE_RANGE")weasyprint_dll_directories= weasyprint_dll_directories if weasyprint_dll_directories else Noneconfig_load_models.weasyprint_libpath = weasyprint_dll_directories ## Assign user's weasyprint path to Global varprogress((3,16), desc=f"Retrieved configuration values")time.sleep(0.25)160 unmodified lines161162163164165166167160 unmodified linespage_range = page_range if page_range else get_config_value(config_file,"MARKER_CAP", "PAGE_RANGE")weasyprint_dll_directories= weasyprint_dll_directories if weasyprint_dll_directories else Noneconfig_load_models.weasyprint_libpath = weasyprint_dll_directories ## Assign user's weasyprint path to Global varconfig_load_models.pdf_files_count = pdf_files_countprogress((3,16), desc=f"Retrieved configuration values")time.sleep(0.25)
converters/pdf_to_md.py+7-3
globals.py+1
ui/gradio_ui.py+1