Update app.py
Browse files
app.py
CHANGED
|
@@ -10,10 +10,10 @@ import os
|
|
| 10 |
OUTPUT_DIR = "output_results"
|
| 11 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 12 |
|
| 13 |
-
# --- 模型加载器 ---
|
| 14 |
def load_gpu_model():
|
| 15 |
-
print("
|
| 16 |
-
#
|
| 17 |
ocr_model = PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=True)
|
| 18 |
print("GPU模型加载成功。")
|
| 19 |
return ocr_model
|
|
@@ -33,7 +33,7 @@ def process_pdf_max_speed(pdf_file, progress=gr.Progress(track_tqdm=True)):
|
|
| 33 |
|
| 34 |
doc = fitz.open(pdf_file.name)
|
| 35 |
total_pages = len(doc)
|
| 36 |
-
batch_size = 4
|
| 37 |
full_text_result = []
|
| 38 |
|
| 39 |
for i in progress.tqdm(range(0, total_pages, batch_size), desc="🚀 批处理中..."):
|
|
@@ -46,7 +46,6 @@ def process_pdf_max_speed(pdf_file, progress=gr.Progress(track_tqdm=True)):
|
|
| 46 |
batch_images.append(np.array(img))
|
| 47 |
|
| 48 |
if batch_images:
|
| 49 |
-
# 使用与锁定版本兼容的调用方式:需要 cls=True
|
| 50 |
results = ocr.ocr(batch_images, cls=True)
|
| 51 |
|
| 52 |
for page_index, page_result in enumerate(results):
|
|
@@ -77,7 +76,7 @@ def process_pdf_max_speed(pdf_file, progress=gr.Progress(track_tqdm=True)):
|
|
| 77 |
with gr.Blocks(title="极速PDF识别器", theme=gr.themes.Soft()) as demo:
|
| 78 |
gr.Markdown(
|
| 79 |
"""
|
| 80 |
-
#
|
| 81 |
**速度拉满!实时进度显示,处理期间请勿关闭页面。**
|
| 82 |
"""
|
| 83 |
)
|
|
@@ -93,7 +92,7 @@ with gr.Blocks(title="极速PDF识别器", theme=gr.themes.Soft()) as demo:
|
|
| 93 |
submit_btn.click(
|
| 94 |
fn=process_pdf_max_speed,
|
| 95 |
inputs=[pdf_input],
|
| 96 |
-
outputs=[
|
| 97 |
)
|
| 98 |
|
| 99 |
demo.queue().launch()
|
|
|
|
| 10 |
OUTPUT_DIR = "output_results"
|
| 11 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 12 |
|
| 13 |
+
# --- 模型加载器 (这个函数将在GPU容器中被安全调用) ---
|
| 14 |
def load_gpu_model():
|
| 15 |
+
print("正在Docker容器中加载PaddleOCR GPU模型...")
|
| 16 |
+
# 使用与2.7.3版本兼容的参数
|
| 17 |
ocr_model = PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=True)
|
| 18 |
print("GPU模型加载成功。")
|
| 19 |
return ocr_model
|
|
|
|
| 33 |
|
| 34 |
doc = fitz.open(pdf_file.name)
|
| 35 |
total_pages = len(doc)
|
| 36 |
+
batch_size = 4
|
| 37 |
full_text_result = []
|
| 38 |
|
| 39 |
for i in progress.tqdm(range(0, total_pages, batch_size), desc="🚀 批处理中..."):
|
|
|
|
| 46 |
batch_images.append(np.array(img))
|
| 47 |
|
| 48 |
if batch_images:
|
|
|
|
| 49 |
results = ocr.ocr(batch_images, cls=True)
|
| 50 |
|
| 51 |
for page_index, page_result in enumerate(results):
|
|
|
|
| 76 |
with gr.Blocks(title="极速PDF识别器", theme=gr.themes.Soft()) as demo:
|
| 77 |
gr.Markdown(
|
| 78 |
"""
|
| 79 |
+
# ✅ 极速PDF识别器 (终极稳定版) ✅
|
| 80 |
**速度拉满!实时进度显示,处理期间请勿关闭页面。**
|
| 81 |
"""
|
| 82 |
)
|
|
|
|
| 92 |
submit_btn.click(
|
| 93 |
fn=process_pdf_max_speed,
|
| 94 |
inputs=[pdf_input],
|
| 95 |
+
outputs=[display, download_link]
|
| 96 |
)
|
| 97 |
|
| 98 |
demo.queue().launch()
|