diff --git a/chyoso_toolkit_ui.py b/chyoso_toolkit_ui.py index 104c72c..6417ae0 100644 --- a/chyoso_toolkit_ui.py +++ b/chyoso_toolkit_ui.py @@ -2,6 +2,8 @@ import gradio as gr import subprocess import os import re +import pyperclip + def convert_to_wav(audio_file): # 使用 ffmpeg 将音频文件转换为 wav 格式 @@ -76,7 +78,8 @@ def list_files(): # 获取目录下的所有文件 files = os.listdir(batch_directory) # 过滤掉目录,只保留文件 - files = [f for f in files if os.path.isfile(os.path.join(batch_directory, f)) and f.lower().endswith(('.mp3', '.m4a'))] + files = [f for f in files if + os.path.isfile(os.path.join(batch_directory, f)) and f.lower().endswith(('.mp3', '.m4a'))] return files @@ -133,6 +136,7 @@ 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*', '\n ', powershell_script) @@ -142,6 +146,12 @@ def power_shell_pdf_download(powershell_script): powershell_script = powershell_script.strip() + ' -OutFile 1.pdf' return powershell_script + +def copy_text(text): + pyperclip.copy(text) + return "Text copied to clipboard!" + + with gr.Blocks() as iface: gr.Markdown("# 大模型工具集") with gr.Tabs(): @@ -193,14 +203,19 @@ with gr.Blocks() as iface: 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="这里会显示结果") + with gr.Column(): + power_shell_text_input = gr.Textbox(lines=15, placeholder="请在此输入power shell 脚本...") + with gr.Column(): + power_shell_pdf_button = gr.Button("转换") + power_shell_pdf_copy_button = gr.Button("复制") + status_text = gr.Textbox(label="Status") + with gr.Column(): + 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) + power_shell_pdf_button.click(power_shell_pdf_download, inputs=power_shell_text_input, + outputs=power_shell_text_output) + power_shell_pdf_copy_button.click(fn=copy_text, inputs=power_shell_text_output, outputs=status_text) 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 +iface.launch(server_name="0.0.0.0")