rastof9 commited on
Commit
7a81bf6
·
verified ·
1 Parent(s): 1fe409e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ import subprocess
4
+ import shlex
5
+
6
+ def run_command(cmd, history):
7
+ try:
8
+ args = shlex.split(cmd)
9
+ result = subprocess.run(args, capture_output=True, text=True, timeout=10)
10
+ output = result.stdout or result.stderr
11
+ except Exception as e:
12
+ output = str(e)
13
+ new_history = history + f"> {cmd}\n{output}\n"
14
+ return new_history, new_history
15
+
16
+ with gr.Blocks() as demo:
17
+ gr.Markdown("### 🖥️ Simple Web Terminal")
18
+ history = gr.Textbox(label="Terminal", lines=20, interactive=False)
19
+ cmd_input = gr.Textbox(label="Command")
20
+ run_btn = gr.Button("Run")
21
+
22
+ run_btn.click(run_command, inputs=[cmd_input, history], outputs=[history, history])
23
+ cmd_input.submit(run_command, inputs=[cmd_input, history], outputs=[history, history])
24
+
25
+ demo.launch()