Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,7 +70,9 @@ def zip_output_files():
|
|
| 70 |
return ZIP_PATH
|
| 71 |
|
| 72 |
# 主流程
|
| 73 |
-
def process_pdf(pdf_file):
|
|
|
|
|
|
|
| 74 |
try:
|
| 75 |
progress = gr.Progress()
|
| 76 |
progress(0, desc="準備中...")
|
|
@@ -107,7 +109,7 @@ def process_pdf(pdf_file):
|
|
| 107 |
result = overlay_image(bg.copy(), fg, *POS1)
|
| 108 |
result = overlay_image(result, fg, *POS2)
|
| 109 |
|
| 110 |
-
output_path = f"{OUTPUT_DIR}/
|
| 111 |
cv2.imwrite(output_path, result)
|
| 112 |
results.append((output_path, f"Page {i:03d}"))
|
| 113 |
|
|
@@ -130,6 +132,7 @@ with gr.Blocks() as demo:
|
|
| 130 |
gr.Markdown("## 📄 PDF頁面合成工具(背景固定為 7872x1200)")
|
| 131 |
|
| 132 |
pdf_upload = gr.File(label="上傳PDF文件", file_types=[".pdf"])
|
|
|
|
| 133 |
btn_run = gr.Button("開始合成", variant="primary")
|
| 134 |
|
| 135 |
with gr.Row():
|
|
@@ -138,10 +141,10 @@ with gr.Blocks() as demo:
|
|
| 138 |
log_output = gr.Textbox(label="日誌", interactive=False)
|
| 139 |
|
| 140 |
btn_run.click(
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
)
|
| 146 |
|
| 147 |
if __name__ == "__main__":
|
|
|
|
| 70 |
return ZIP_PATH
|
| 71 |
|
| 72 |
# 主流程
|
| 73 |
+
def process_pdf(pdf_file, prefix="result_"):
|
| 74 |
+
if not prefix.strip():
|
| 75 |
+
prefix = "result_"
|
| 76 |
try:
|
| 77 |
progress = gr.Progress()
|
| 78 |
progress(0, desc="準備中...")
|
|
|
|
| 109 |
result = overlay_image(bg.copy(), fg, *POS1)
|
| 110 |
result = overlay_image(result, fg, *POS2)
|
| 111 |
|
| 112 |
+
output_path = f"{OUTPUT_DIR}/{prefix}{i:03d}.jpg"
|
| 113 |
cv2.imwrite(output_path, result)
|
| 114 |
results.append((output_path, f"Page {i:03d}"))
|
| 115 |
|
|
|
|
| 132 |
gr.Markdown("## 📄 PDF頁面合成工具(背景固定為 7872x1200)")
|
| 133 |
|
| 134 |
pdf_upload = gr.File(label="上傳PDF文件", file_types=[".pdf"])
|
| 135 |
+
prefix_input = gr.Textbox(label="輸出檔案前綴 (選填)", placeholder="例如:invoice_")
|
| 136 |
btn_run = gr.Button("開始合成", variant="primary")
|
| 137 |
|
| 138 |
with gr.Row():
|
|
|
|
| 141 |
log_output = gr.Textbox(label="日誌", interactive=False)
|
| 142 |
|
| 143 |
btn_run.click(
|
| 144 |
+
fn=process_pdf,
|
| 145 |
+
inputs=[pdf_upload, prefix_input],
|
| 146 |
+
outputs=[gallery, zip_download, log_output],
|
| 147 |
+
concurrency_limit=4
|
| 148 |
)
|
| 149 |
|
| 150 |
if __name__ == "__main__":
|