Spaces:
Running
Running
fix: process pdf once
Browse files
app.py
CHANGED
@@ -45,12 +45,10 @@ def ocr_process(file, got_mode, ocr_color="", ocr_box="", progress=gr.Progress()
|
|
45 |
progress(0, desc="开始处理...")
|
46 |
|
47 |
with tempfile.TemporaryDirectory() as temp_dir:
|
48 |
-
|
49 |
-
pdf_path = os.path.join(temp_dir, "temp.pdf")
|
50 |
-
with open(pdf_path, "wb") as f:
|
51 |
-
f.write(file.read())
|
52 |
|
53 |
-
|
|
|
54 |
num_pages = len(images)
|
55 |
results = []
|
56 |
|
@@ -64,10 +62,7 @@ def ocr_process(file, got_mode, ocr_color="", ocr_box="", progress=gr.Progress()
|
|
64 |
|
65 |
final_result = "\n\n".join(results)
|
66 |
else:
|
67 |
-
|
68 |
-
with open(img_path, "wb") as f:
|
69 |
-
f.write(file.read())
|
70 |
-
final_result = process_single_image(img_path, got_mode, ocr_color, ocr_box)
|
71 |
|
72 |
progress(1, desc="处理完成")
|
73 |
return final_result
|
|
|
45 |
progress(0, desc="开始处理...")
|
46 |
|
47 |
with tempfile.TemporaryDirectory() as temp_dir:
|
48 |
+
file_path = file.name # 使用文件的原始路径
|
|
|
|
|
|
|
49 |
|
50 |
+
if file_path.lower().endswith(".pdf"):
|
51 |
+
images = pdf_to_images(file_path)
|
52 |
num_pages = len(images)
|
53 |
results = []
|
54 |
|
|
|
62 |
|
63 |
final_result = "\n\n".join(results)
|
64 |
else:
|
65 |
+
final_result = process_single_image(file_path, got_mode, ocr_color, ocr_box)
|
|
|
|
|
|
|
66 |
|
67 |
progress(1, desc="处理完成")
|
68 |
return final_result
|