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)