terminal4 / app.py
skanaujiya's picture
Update app.py
eec2447 verified
raw
history blame
2.44 kB
import streamlit as st
import subprocess
# Set the page layout to wide mode for a cleaner look
st.set_page_config(page_title="Terminal Command Executor", layout="centered")
# Main title with emojis for visual appeal
st.title("๐Ÿš€ Run Terminal Commands Easily")
# Brief description to guide the user
st.markdown("""
### Simple and intuitive tool to execute terminal commands directly from this interface.
Just enter a command, hit the button, and see the output below.
""")
# Create a larger and clearer input field with a placeholder
command = st.text_input("๐Ÿ’ป Enter a terminal command", placeholder="e.g., ls, pwd, echo Hello World", max_chars=100)
# Button to run the command
run_button = st.button("Run Command")
# Display the output when the command is executed
if run_button and command:
with st.spinner("Running command..."):
try:
# Run the terminal command and capture output
result = subprocess.run(command, shell=True, capture_output=True, text=True)
# Display success message and output
st.success("โœ… Command executed successfully!")
st.code(result.stdout, language="bash")
# Display any errors in red
if result.stderr:
st.error(f"โš ๏ธ Error:\n{result.stderr}")
except Exception as e:
st.error(f"โŒ Failed to run command: {e}")
else:
if run_button:
st.warning("โš ๏ธ Please enter a command.")
# Custom CSS to simplify and style the UI
st.markdown("""
<style>
/* Hide footer */
footer {visibility: hidden;}
/* Increase input box size and font */
.stTextInput input {
font-size: 16px;
height: 50px;
width: 100%;
padding: 10px;
border-radius: 5px;
border: 1px solid #3498db;
background-color: #f0f4f8;
color: #333;
}
/* Customize button */
.stButton button {
background-color: #3498db;
color: white;
font-size: 16px;
padding: 8px 16px;
border-radius: 5px;
border: none;
}
/* Set the success and warning messages to look cleaner */
.stAlert {
font-size: 15px;
}
/* Customize code display */
.stCodeBlock {
background-color: #2c3e50;
color: #ecf0f1;
padding: 10px;
border-radius: 5px;
}
</style>
""", unsafe_allow_html=True)