From 6da40735f6bc8935d857b968a50acee2e08d0def Mon Sep 17 00:00:00 2001 From: William Jin Date: Sun, 22 Sep 2024 21:09:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=20pdf=20=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chyoso_toolkit_ui.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/chyoso_toolkit_ui.py b/chyoso_toolkit_ui.py index 4af2514..eb84b30 100644 --- a/chyoso_toolkit_ui.py +++ b/chyoso_toolkit_ui.py @@ -1,7 +1,7 @@ import gradio as gr import subprocess import os - +import re def convert_to_wav(audio_file): # 使用 ffmpeg 将音频文件转换为 wav 格式 @@ -133,6 +133,14 @@ def convert_to_docx(text): # 返回 file.docx 文件供用户下载 return "file.docx" +def power_shell_pdf_download(powershell_script): + # 使用正则表达式去除 if-none-match 和 range 标头 + powershell_script = re.sub(r'\s*"if-none-match"="`"[^"]*`""\s*', '', powershell_script) + powershell_script = re.sub(r'\s*"range"="[^"]*"\s*', '', powershell_script) + + # 在脚本最后加上 "-OutFile 1.pdf" + powershell_script = powershell_script.strip() + '\n-OutFile 1.pdf' + return powershell_script with gr.Blocks() as iface: gr.Markdown("# 大模型工具集") @@ -182,6 +190,17 @@ with gr.Blocks() as iface: convert_button.click(convert_to_docx, inputs=text_input, outputs=output_file) + with gr.Tab("下载pdf"): + gr.Markdown("## pdf 下载指令修复") + with gr.Row(): + power_shell_text_input = gr.Textbox(lines=15, placeholder="请在此输入power shell 脚本...") + with gr.Row(): + power_shell_pdf_button = gr.Button("转换") + with gr.Row(): + power_shell_text_output = gr.Textbox(lines=15, placeholder="这里会显示结果") + + power_shell_pdf_button.click(power_shell_pdf_download, inputs=power_shell_text_input, outputs=power_shell_text_output) + iface.load(fn=update_log_output, outputs=[log_output], every=1) iface.launch(server_name="0.0.0.0") \ No newline at end of file