File size: 960 Bytes
e3b254d
 
 
 
 
b440a19
e3b254d
b440a19
e3b254d
b440a19
e3b254d
 
 
b440a19
e3b254d
b440a19
 
 
e3b254d
 
 
b440a19
 
e3b254d
 
b440a19
 
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
import subprocess
import gradio as gr

def execute_command(command):
    try:
        # Execute the command and capture the output
        result = subprocess.run(
            command, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )
        # Combine stdout and stderr for display
        output = result.stdout + result.stderr
        return output.strip() if output else "No output"
    except Exception as e:
        return f"Error: {str(e)}"

# Gradio interface
with gr.Blocks() as linux_emulator:
    gr.Markdown("## Linux Terminal Emulator")
    command_input = gr.Textbox(label="Enter Command", placeholder="e.g., ls, pwd, whoami")
    output_display = gr.Textbox(label="Output", interactive=False)
    execute_button = gr.Button("Execute Command")
    
    # Button click behavior
    execute_button.click(fn=execute_command, inputs=command_input, outputs=output_display)

# Launch the interface
linux_emulator.launch()