Update app.py
Browse files
app.py
CHANGED
@@ -39,24 +39,20 @@ if 'history' not in st.session_state:
|
|
39 |
def run_command(command):
|
40 |
try:
|
41 |
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
except Exception as e:
|
45 |
-
st.
|
46 |
-
st.session_state.output = None
|
47 |
|
48 |
-
# Layout with
|
49 |
-
col1, col2
|
50 |
|
51 |
-
# Command
|
52 |
with col1:
|
53 |
-
st.subheader("Command History")
|
54 |
-
for cmd in reversed(st.session_state.history):
|
55 |
-
if st.button(f"Run: {cmd}", key=cmd):
|
56 |
-
run_command(cmd)
|
57 |
-
|
58 |
-
# Command input in the second column
|
59 |
-
with col2:
|
60 |
command = st.text_area("Enter terminal command", placeholder="e.g., ls, pwd, echo 'Hello World'", height=100)
|
61 |
if st.button("Run Command"):
|
62 |
if command:
|
@@ -67,13 +63,12 @@ with col2:
|
|
67 |
else:
|
68 |
st.warning("Please enter a command to run.")
|
69 |
|
70 |
-
#
|
71 |
-
with
|
72 |
-
st.subheader("
|
73 |
-
|
74 |
-
st.
|
75 |
-
|
76 |
-
st.markdown(f'<div class="error">{st.session_state.error}</div>', unsafe_allow_html=True)
|
77 |
|
78 |
# Optional file upload (if needed)
|
79 |
uploaded_file = st.file_uploader("Upload a file to process with command:", type=["txt", "csv"])
|
|
|
39 |
def run_command(command):
|
40 |
try:
|
41 |
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
42 |
+
if result.stdout:
|
43 |
+
st.subheader("Output:")
|
44 |
+
st.markdown(f'<div class="output">{result.stdout}</div>', unsafe_allow_html=True)
|
45 |
+
if result.stderr:
|
46 |
+
st.subheader("Error:")
|
47 |
+
st.markdown(f'<div class="error">{result.stderr}</div>', unsafe_allow_html=True)
|
48 |
except Exception as e:
|
49 |
+
st.error(f"An error occurred: {e}")
|
|
|
50 |
|
51 |
+
# Layout with columns
|
52 |
+
col1, col2 = st.columns([2, 1])
|
53 |
|
54 |
+
# Command input and button in the first column
|
55 |
with col1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
command = st.text_area("Enter terminal command", placeholder="e.g., ls, pwd, echo 'Hello World'", height=100)
|
57 |
if st.button("Run Command"):
|
58 |
if command:
|
|
|
63 |
else:
|
64 |
st.warning("Please enter a command to run.")
|
65 |
|
66 |
+
# Command history display in the second column
|
67 |
+
with col2:
|
68 |
+
st.subheader("Command History")
|
69 |
+
for cmd in reversed(st.session_state.history):
|
70 |
+
if st.button(f"Run: {cmd}", key=cmd):
|
71 |
+
run_command(cmd)
|
|
|
72 |
|
73 |
# Optional file upload (if needed)
|
74 |
uploaded_file = st.file_uploader("Upload a file to process with command:", type=["txt", "csv"])
|