Update app.py
Browse files
app.py
CHANGED
@@ -3,39 +3,28 @@ import subprocess
|
|
3 |
|
4 |
def execute_command(command):
|
5 |
try:
|
|
|
6 |
result = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, universal_newlines=True)
|
7 |
except subprocess.CalledProcessError as e:
|
8 |
result = e.output
|
9 |
return result
|
10 |
|
11 |
-
def bash_terminal(command):
|
12 |
-
output = execute_command(command)
|
13 |
-
return output
|
14 |
-
|
15 |
-
# 定義 Gradio 界面
|
16 |
def gradio_app():
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
inputs=command_input,
|
33 |
-
outputs=[command_output, execute_button],
|
34 |
-
live=True,
|
35 |
-
title="Bash Terminal",
|
36 |
-
description="在線 Bash Terminal,輸入指令並執行。",
|
37 |
-
capture_session=True
|
38 |
-
)
|
39 |
|
40 |
# 啟動 Gradio 應用程序
|
41 |
iface = gradio_app()
|
|
|
3 |
|
4 |
def execute_command(command):
|
5 |
try:
|
6 |
+
# 執行命令並捕獲輸出
|
7 |
result = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, universal_newlines=True)
|
8 |
except subprocess.CalledProcessError as e:
|
9 |
result = e.output
|
10 |
return result
|
11 |
|
|
|
|
|
|
|
|
|
|
|
12 |
def gradio_app():
|
13 |
+
# 定義一個函數來處理指令的執行
|
14 |
+
def run_command(command):
|
15 |
+
output = execute_command(command)
|
16 |
+
return output
|
17 |
+
|
18 |
+
# 創建 Gradio 界面
|
19 |
+
with gr.Blocks() as demo:
|
20 |
+
command_input = gr.Textbox(label="輸入指令", placeholder="輸入你要執行的 Bash 指令")
|
21 |
+
command_output = gr.Textbox(label="指令輸出", lines=24, cols=80, placeholder="指令的輸出結果", readonly=True)
|
22 |
+
|
23 |
+
# 設置按鈕和回調函數
|
24 |
+
execute_button = gr.Button("執行指令")
|
25 |
+
execute_button.click(fn=run_command, inputs=command_input, outputs=command_output)
|
26 |
+
|
27 |
+
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# 啟動 Gradio 應用程序
|
30 |
iface = gradio_app()
|