From 17a6524697c19b838f38c41367a915e26f7c8005 Mon Sep 17 00:00:00 2001 From: William Jin Date: Mon, 23 Sep 2024 07:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8B=E8=BD=BD=20pdf=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E8=BE=93=E5=85=A5=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chyoso_toolkit_ui.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/chyoso_toolkit_ui.py b/chyoso_toolkit_ui.py index cdc4f1c..2327a27 100644 --- a/chyoso_toolkit_ui.py +++ b/chyoso_toolkit_ui.py @@ -143,7 +143,7 @@ def remove_headers(curl_command): return curl_command -def do_download_pdf_file(curl_command): +def do_download_pdf_file(curl_command, pdf_filename): # 去除不需要的标头 curl_command = remove_headers(curl_command) @@ -151,7 +151,10 @@ def do_download_pdf_file(curl_command): try: result = subprocess.run(curl_command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # 保存文件到临时文件 - temp_file_path = "./download.pdf" + if pdf_filename != "": + temp_file_path = f"./{pdf_filename}.pdf" + else: + temp_file_path = "./download.pdf" with open(temp_file_path, 'wb') as f: f.write(result.stdout) return "File downloaded successfully", temp_file_path @@ -159,8 +162,8 @@ def do_download_pdf_file(curl_command): return f"Failed to download file. Error: {e.stderr.decode()}", None -def download_pdf(curl_command): - message, file_path = do_download_pdf_file(curl_command) +def download_pdf(curl_command, pdf_filename): + message, file_path = do_download_pdf_file(curl_command, pdf_filename) return file_path @@ -217,11 +220,14 @@ with gr.Blocks() as iface: with gr.Row(): curl_text_input = gr.Textbox(lines=10, placeholder="请在此输入cURL脚本...") with gr.Row(): - pdf_download_button = gr.Button("下载") + with gr.Column(): + pdf_filename = gr.Textbox(placeholder="输入文件名") + with gr.Column(): + pdf_download_button = gr.Button("下载") with gr.Row(): pdf_download_result = gr.File(label="下载pdf文件") - pdf_download_button.click(download_pdf, inputs=curl_text_input, outputs=pdf_download_result) + pdf_download_button.click(download_pdf, inputs=[curl_text_input, pdf_filename], outputs=pdf_download_result) iface.load(fn=update_log_output, outputs=[log_output], every=1)