Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
| 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: {str(e)}"
|
| 15 |
+
|
| 16 |
+
# Gradio interface
|
| 17 |
+
with gr.Blocks() as linux_emulator:
|
| 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 |
+
# Button click behavior
|
| 24 |
+
execute_button.click(fn=execute_command, inputs=command_input, outputs=output_display)
|
| 25 |
+
|
| 26 |
+
# Launch the interface
|
| 27 |
+
linux_emulator.launch()
|