Termux_web / app.py
bk939448's picture
Update app.py
452a567 verified
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()