Download app.py from rastof9/terminal: direct link, hf CLI and curl.
- Browser
- Download file 825 Bytes
-
https://huggingface.co/spaces/rastof9/terminal/resolve/main/app.py
- Command line
-
hf download hf://spaces/rastof9/terminal/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rastof9/terminal/resolve/main/app.py
825 Bytes
| # app.py | |
| import gradio as gr | |
| import subprocess | |
| import shlex | |
| def run_command(cmd, history): | |
| try: | |
| args = shlex.split(cmd) | |
| result = subprocess.run(args, capture_output=True, text=True, timeout=10) | |
| output = result.stdout or result.stderr | |
| except Exception as e: | |
| output = str(e) | |
| new_history = history + f"> {cmd}\n{output}\n" | |
| return new_history, new_history | |
| with gr.Blocks() as demo: | |
| gr.Markdown("### 🖥️ Simple Web Terminal") | |
| history = gr.Textbox(label="Terminal", lines=20, interactive=False) | |
| cmd_input = gr.Textbox(label="Command") | |
| run_btn = gr.Button("Run") | |
| run_btn.click(run_command, inputs=[cmd_input, history], outputs=[history, history]) | |
| cmd_input.submit(run_command, inputs=[cmd_input, history], outputs=[history, history]) | |
| demo.launch() | |