openfree commited on
Commit
630dc5d
Β·
verified Β·
1 Parent(s): fdc1e97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -34
app.py CHANGED
@@ -150,43 +150,40 @@ def to_pdf(file_path):
150
  return tmp_file_path
151
 
152
  def to_markdown(file_path, end_pages, is_ocr, layout_mode, formula_enable, table_enable, language, progress=gr.Progress(track_tqdm=False)):
153
- """
154
- - PDF λ³€ν™˜ κ³Όμ • λ‹¨κ³„λ³„λ‘œ progress ν‘œμ‹œ
155
- - λ°˜ν™˜κ°’: μ΅œμ’… λ§ˆν¬λ‹€μš΄ ν…μŠ€νŠΈ
156
- """
157
- with progress:
158
- progress(0, "νŒŒμΌμ„ PDF둜 λ³€ν™˜ 쀑...")
159
- file_path = to_pdf(file_path)
160
- time.sleep(0.5) # μ˜ˆμ‹œλ‘œ λ”œλ ˆμ΄
161
-
162
- if end_pages > 20:
163
- end_pages = 20
164
- progress(30, "PDF νŒŒμ‹± 쀑...")
165
- local_md_dir, file_name = parse_pdf(file_path, './output', end_pages - 1, is_ocr,
166
- layout_mode, formula_enable, table_enable, language)
167
- time.sleep(0.5)
168
-
169
- progress(50, "μ••μΆ•(Zip) 생성 쀑...")
170
- archive_zip_path = os.path.join("./output", compute_sha256(local_md_dir) + ".zip")
171
- zip_archive_success = compress_directory_to_zip(local_md_dir, archive_zip_path)
172
- if zip_archive_success == 0:
173
- logger.info("μ••μΆ• 성곡")
174
- else:
175
- logger.error("μ••μΆ• μ‹€νŒ¨")
176
- time.sleep(0.5)
 
 
177
 
178
- progress(70, "λ§ˆν¬λ‹€μš΄ μ½λŠ” 쀑...")
179
- md_path = os.path.join(local_md_dir, file_name + ".md")
180
- with open(md_path, 'r', encoding='utf-8') as f:
181
- txt_content = f.read()
182
- time.sleep(0.5)
183
 
184
- progress(90, "이미지 base64 λ³€ν™˜ 쀑...")
185
- md_content = replace_image_with_base64(txt_content, local_md_dir)
186
- time.sleep(0.5)
187
 
188
- progress(100, "λ³€ν™˜ μ™„λ£Œ!")
189
- return md_content
190
 
191
  def init_model():
192
  from magic_pdf.model.doc_analyze_by_custom_model import ModelSingleton
 
150
  return tmp_file_path
151
 
152
  def to_markdown(file_path, end_pages, is_ocr, layout_mode, formula_enable, table_enable, language, progress=gr.Progress(track_tqdm=False)):
153
+ progress(0, "νŒŒμΌμ„ PDF둜 λ³€ν™˜ 쀑...")
154
+ file_path = to_pdf(file_path)
155
+ time.sleep(0.5)
156
+
157
+ if end_pages > 20:
158
+ end_pages = 20
159
+
160
+ progress(30, "PDF νŒŒμ‹± 쀑...")
161
+ local_md_dir, file_name = parse_pdf(file_path, './output', end_pages - 1, is_ocr,
162
+ layout_mode, formula_enable, table_enable, language)
163
+ time.sleep(0.5)
164
+
165
+ progress(50, "μ••μΆ•(Zip) 생성 쀑...")
166
+ archive_zip_path = os.path.join("./output", compute_sha256(local_md_dir) + ".zip")
167
+ zip_archive_success = compress_directory_to_zip(local_md_dir, archive_zip_path)
168
+ if zip_archive_success == 0:
169
+ logger.info("μ••μΆ• 성곡")
170
+ else:
171
+ logger.error("μ••μΆ• μ‹€νŒ¨")
172
+ time.sleep(0.5)
173
+
174
+ progress(70, "λ§ˆν¬λ‹€μš΄ μ½λŠ” 쀑...")
175
+ md_path = os.path.join(local_md_dir, file_name + ".md")
176
+ with open(md_path, 'r', encoding='utf-8') as f:
177
+ txt_content = f.read()
178
+ time.sleep(0.5)
179
 
180
+ progress(90, "이미지 base64 λ³€ν™˜ 쀑...")
181
+ md_content = replace_image_with_base64(txt_content, local_md_dir)
182
+ time.sleep(0.5)
 
 
183
 
184
+ progress(100, "λ³€ν™˜ μ™„λ£Œ!")
185
+ return md_content
 
186
 
 
 
187
 
188
  def init_model():
189
  from magic_pdf.model.doc_analyze_by_custom_model import ModelSingleton