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