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()