Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,25 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
|
| 4 |
+
def run_command(command):
|
| 5 |
+
try:
|
| 6 |
+
# Run the command and capture the output
|
| 7 |
+
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
| 8 |
+
|
| 9 |
+
# Return the output or any error encountered
|
| 10 |
+
if result.returncode == 0:
|
| 11 |
+
return f"Output:\n{result.stdout}"
|
| 12 |
+
else:
|
| 13 |
+
return f"Error:\n{result.stderr}"
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return str(e)
|
| 16 |
|
| 17 |
+
# Create a Gradio interface
|
| 18 |
+
iface = gr.Interface(fn=run_command,
|
| 19 |
+
inputs="text",
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="Linux Command Runner",
|
| 22 |
+
description="Enter a Linux command to execute and see the output.")
|
| 23 |
+
|
| 24 |
+
# Launch the interface
|
| 25 |
+
iface.launch()
|