bk939448 commited on
Commit
f264926
·
verified ·
1 Parent(s): 8f3a9c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+
4
+ def run_command(cmd):
5
+ try:
6
+ if not cmd.strip():
7
+ return "⚠️ Please enter a command."
8
+ output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, timeout=10)
9
+ return output.decode("utf-8")
10
+ except subprocess.CalledProcessError as e:
11
+ return f"❌ Error:\n{e.output.decode('utf-8')}"
12
+ except Exception as e:
13
+ return f"💥 Exception:\n{str(e)}"
14
+
15
+ custom_css = """
16
+ #terminal-output textarea {
17
+ background-color: #000000 !important;
18
+ color: #00FF00 !important;
19
+ font-family: monospace !important;
20
+ font-size: 14px;
21
+ }
22
+ #terminal-input textarea {
23
+ background-color: #111111 !important;
24
+ color: #00FF00 !important;
25
+ font-family: monospace !important;
26
+ font-size: 14px;
27
+ }
28
+ """
29
+
30
+ with gr.Blocks(css=custom_css, title="Termux Styled Terminal") as demo:
31
+ gr.Markdown("## 💻 <span style='color:#00FF00;'>HuggingFace Terminal Emulator</span>", unsafe_allow_html=True)
32
+
33
+ with gr.Row():
34
+ cmd_input = gr.Textbox(label="🔸 Terminal Command", elem_id="terminal-input", placeholder="ls -la", lines=1)
35
+ run_button = gr.Button("🚀 Run Command")
36
+
37
+ output_box = gr.Textbox(label="🔹 Output", elem_id="terminal-output", lines=18, interactive=False)
38
+
39
+ run_button.click(fn=run_command, inputs=cmd_input, outputs=output_box)
40
+
41
+ demo.launch()