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("

💻 HuggingFace Terminal Emulator

") 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()