codeBOKER commited on
Commit
2f3f2a4
·
verified ·
1 Parent(s): fa39d87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -12
app.py CHANGED
@@ -5,9 +5,7 @@ import gradio as gr
5
  def run_command(cmd):
6
  if not cmd.strip():
7
  return "Please enter a valid command."
8
-
9
  try:
10
- # Run terminal command and capture output
11
  result = subprocess.run(
12
  cmd,
13
  shell=True,
@@ -16,32 +14,25 @@ def run_command(cmd):
16
  timeout=60,
17
  cwd=os.getcwd()
18
  )
19
-
20
  output = result.stdout
21
  if result.stderr:
22
  output += f"\n[STDERR]\n{result.stderr}"
23
-
24
  return output if output else "Command completed with no output."
25
  except Exception as e:
26
  return f"Error executing command: {str(e)}"
27
 
28
- # Build simple Gradio UI
29
  with gr.Blocks(title="Gradio Terminal") as demo:
30
  gr.Markdown("## 🛠️ Gradio Terminal Executor")
31
 
32
  with gr.Row():
33
- cmd_input = gr.Textbox(
34
- placeholder="Type command here (e.g., node -v, pip list, or npm install)...",
35
- label="Command",
36
- scale=4
37
- )
38
  run_btn = gr.Button("Run", scale=1)
39
 
40
  output_box = gr.Code(label="Terminal Output", language="shell", interactive=False)
41
 
42
- # Trigger via button click or pressing Enter
43
  run_btn.click(fn=run_command, inputs=cmd_input, outputs=output_box)
44
  cmd_input.submit(fn=run_command, inputs=cmd_input, outputs=output_box)
45
 
46
  if __name__ == "__main__":
47
- demo.launch()
 
 
5
  def run_command(cmd):
6
  if not cmd.strip():
7
  return "Please enter a valid command."
 
8
  try:
 
9
  result = subprocess.run(
10
  cmd,
11
  shell=True,
 
14
  timeout=60,
15
  cwd=os.getcwd()
16
  )
 
17
  output = result.stdout
18
  if result.stderr:
19
  output += f"\n[STDERR]\n{result.stderr}"
 
20
  return output if output else "Command completed with no output."
21
  except Exception as e:
22
  return f"Error executing command: {str(e)}"
23
 
 
24
  with gr.Blocks(title="Gradio Terminal") as demo:
25
  gr.Markdown("## 🛠️ Gradio Terminal Executor")
26
 
27
  with gr.Row():
28
+ cmd_input = gr.Textbox(placeholder="Type command here...", label="Command", scale=4)
 
 
 
 
29
  run_btn = gr.Button("Run", scale=1)
30
 
31
  output_box = gr.Code(label="Terminal Output", language="shell", interactive=False)
32
 
 
33
  run_btn.click(fn=run_command, inputs=cmd_input, outputs=output_box)
34
  cmd_input.submit(fn=run_command, inputs=cmd_input, outputs=output_box)
35
 
36
  if __name__ == "__main__":
37
+ # Disable SSR mode to stop Node.js server crashes
38
+ demo.launch(ssr_mode=False, server_name="0.0.0.0", server_port=7860)