Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import subprocess | |
| def run_command(cmd): | |
| try: | |
| if not cmd.strip(): | |
| return "β οΈ Please enter a command." | |
| output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, timeout=10) | |
| return output.decode("utf-8") | |
| except subprocess.CalledProcessError as e: | |
| return f"β Error:\n{e.output.decode('utf-8')}" | |
| except Exception as e: | |
| return f"π₯ Exception:\n{str(e)}" | |
| custom_css = """ | |
| #terminal-output textarea { | |
| background-color: #000000 !important; | |
| color: #00FF00 !important; | |
| font-family: monospace !important; | |
| font-size: 14px; | |
| } | |
| #terminal-input textarea { | |
| background-color: #111111 !important; | |
| color: #00FF00 !important; | |
| font-family: monospace !important; | |
| font-size: 14px; | |
| } | |
| #title-heading { | |
| color: #00FF00 !important; | |
| font-family: monospace !important; | |
| font-size: 20px; | |
| text-align: center; | |
| } | |
| """ | |
| with gr.Blocks(css=custom_css, title="Termux Styled Terminal") as demo: | |
| gr.HTML("<h2 id='title-heading'>π» HuggingFace Terminal Emulator</h2>") | |
| with gr.Row(): | |
| cmd_input = gr.Textbox(label="πΈ Terminal Command", elem_id="terminal-input", placeholder="ls -la", lines=1) | |
| run_button = gr.Button("π Run Command") | |
| output_box = gr.Textbox(label="πΉ Output", elem_id="terminal-output", lines=18, interactive=False) | |
| run_button.click(fn=run_command, inputs=cmd_input, outputs=output_box) | |
| demo.launch() |