File size: 1,485 Bytes
f264926
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452a567
 
 
 
 
 
f264926
 
 
452a567
f264926
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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()