Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,43 @@
|
|
| 1 |
import subprocess
|
| 2 |
import gradio as gr
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def execute_command(command):
|
| 5 |
try:
|
| 6 |
-
# Execute the command and capture the output
|
| 7 |
result = subprocess.run(
|
| 8 |
-
command,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
)
|
| 10 |
-
# Combine stdout and stderr for display
|
| 11 |
output = result.stdout + result.stderr
|
| 12 |
return output.strip() if output else "No output"
|
| 13 |
except Exception as e:
|
| 14 |
-
return f"Error: {
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
gr.Markdown("## Linux Terminal Emulator")
|
| 19 |
command_input = gr.Textbox(label="Enter Command", placeholder="e.g., ls, pwd, whoami")
|
| 20 |
output_display = gr.Textbox(label="Output", interactive=False)
|
| 21 |
execute_button = gr.Button("Execute Command")
|
| 22 |
-
|
| 23 |
-
|
| 24 |
execute_button.click(fn=execute_command, inputs=command_input, outputs=output_display)
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
linux_emulator.launch()
|
|
|
|
| 1 |
import subprocess
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
def install_sudo():
|
| 5 |
+
try:
|
| 6 |
+
# Try installing sudo
|
| 7 |
+
install_command = "apt update && apt install -y sudo"
|
| 8 |
+
result = subprocess.run(
|
| 9 |
+
install_command,
|
| 10 |
+
shell=True,
|
| 11 |
+
text=True,
|
| 12 |
+
stdout=subprocess.PIPE,
|
| 13 |
+
stderr=subprocess.PIPE
|
| 14 |
+
)
|
| 15 |
+
return f"Output:\n{result.stdout}\nErrors:\n{result.stderr}"
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return f"Error: {e}"
|
| 18 |
+
|
| 19 |
def execute_command(command):
|
| 20 |
try:
|
|
|
|
| 21 |
result = subprocess.run(
|
| 22 |
+
command,
|
| 23 |
+
shell=True,
|
| 24 |
+
text=True,
|
| 25 |
+
stdout=subprocess.PIPE,
|
| 26 |
+
stderr=subprocess.PIPE
|
| 27 |
)
|
|
|
|
| 28 |
output = result.stdout + result.stderr
|
| 29 |
return output.strip() if output else "No output"
|
| 30 |
except Exception as e:
|
| 31 |
+
return f"Error: {e}"
|
| 32 |
|
| 33 |
+
with gr.Blocks() as terminal_with_sudo:
|
| 34 |
+
gr.Markdown("## Linux Terminal Emulator with Sudo Installer")
|
|
|
|
| 35 |
command_input = gr.Textbox(label="Enter Command", placeholder="e.g., ls, pwd, whoami")
|
| 36 |
output_display = gr.Textbox(label="Output", interactive=False)
|
| 37 |
execute_button = gr.Button("Execute Command")
|
| 38 |
+
install_button = gr.Button("Install Sudo")
|
| 39 |
+
|
| 40 |
execute_button.click(fn=execute_command, inputs=command_input, outputs=output_display)
|
| 41 |
+
install_button.click(fn=install_sudo, inputs=[], outputs=output_display)
|
| 42 |
|
| 43 |
+
terminal_with_sudo.launch()
|
|
|