增加下载 pdf 文件名输入框
This commit is contained in:
parent
5d5ec57e3c
commit
17a6524697
@ -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,6 +151,9 @@ def do_download_pdf_file(curl_command):
|
||||
try:
|
||||
result = subprocess.run(curl_command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
# 保存文件到临时文件
|
||||
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)
|
||||
@ -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():
|
||||
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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user