| | import gradio as gr |
| | import subprocess |
| |
|
| | def execute_command(command): |
| | try: |
| | |
| | result = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, universal_newlines=True) |
| | except subprocess.CalledProcessError as e: |
| | result = e.output |
| | return result |
| |
|
| | def gradio_app(): |
| | |
| | def run_command(command): |
| | output = execute_command(command) |
| | return output |
| |
|
| | |
| | with gr.Blocks() as demo: |
| | command_input = gr.Textbox(label="輸入指令", placeholder="輸入你要執行的 Bash 指令", lines=1) |
| | command_output = gr.Textbox(label="指令輸出", placeholder="指令的輸出結果", lines=24, interactive=False) |
| | |
| | |
| | execute_button = gr.Button("執行指令") |
| | execute_button.click(fn=run_command, inputs=command_input, outputs=command_output) |
| | |
| | return demo |
| |
|
| | |
| | iface = gradio_app() |
| | iface.launch() |
| |
|