Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,76 @@
|
|
1 |
import streamlit as st
|
2 |
import subprocess
|
3 |
|
4 |
-
#
|
5 |
-
st.title("
|
|
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Create a button to execute the command
|
11 |
if st.button("Run Command"):
|
12 |
if command:
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
st.
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
else:
|
25 |
-
st.warning("Please enter a command to run.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
# A footer for better UI
|
28 |
st.markdown("""
|
29 |
<style>
|
30 |
-
footer {
|
31 |
-
|
32 |
-
}
|
33 |
-
.css-18e3th9 {
|
34 |
-
background-color: #2c3e50;
|
35 |
-
}
|
36 |
-
h1 {
|
37 |
-
color: #3498db;
|
38 |
-
}
|
39 |
.stTextInput input {
|
40 |
-
border: 1px solid #
|
|
|
41 |
}
|
42 |
.stButton button {
|
43 |
-
background-color: #
|
44 |
color: white;
|
|
|
|
|
|
|
|
|
45 |
}
|
46 |
.stTextArea textarea {
|
47 |
border-color: #3498db;
|
48 |
}
|
|
|
|
|
|
|
49 |
</style>
|
50 |
-
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import subprocess
|
3 |
|
4 |
+
# Sidebar for user instructions and input
|
5 |
+
st.sidebar.title("Terminal Command Runner")
|
6 |
+
st.sidebar.write("Enter a terminal command below, and click the **Run Command** button to execute it.")
|
7 |
|
8 |
+
# Main page layout
|
9 |
+
st.title("🚀 Terminal Command Executor")
|
10 |
+
st.markdown("""
|
11 |
+
This tool allows you to run terminal commands directly from the web interface.
|
12 |
+
Enter a command in the input field, and the output will be displayed below.
|
13 |
+
""")
|
14 |
+
|
15 |
+
# Create a user-friendly input field with a placeholder and description
|
16 |
+
command = st.text_input("💻 Enter a terminal command:", placeholder="e.g., ls, pwd, echo Hello World")
|
17 |
|
18 |
# Create a button to execute the command
|
19 |
if st.button("Run Command"):
|
20 |
if command:
|
21 |
+
with st.spinner("Running the command..."):
|
22 |
+
try:
|
23 |
+
# Execute the terminal command and capture the output
|
24 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
25 |
+
|
26 |
+
# Display the output in the Streamlit app
|
27 |
+
st.success("Command executed successfully!")
|
28 |
+
st.subheader("📜 Command Output:")
|
29 |
+
st.code(result.stdout, language="bash")
|
30 |
+
|
31 |
+
# Display errors, if any
|
32 |
+
if result.stderr:
|
33 |
+
st.error(f"⚠️ Error:\n{result.stderr}")
|
34 |
+
except Exception as e:
|
35 |
+
st.error(f"❌ Error running command: {e}")
|
36 |
else:
|
37 |
+
st.warning("⚠️ Please enter a command to run.")
|
38 |
+
|
39 |
+
# Display additional tips in the sidebar
|
40 |
+
st.sidebar.header("Quick Tips")
|
41 |
+
st.sidebar.write("""
|
42 |
+
- To list files: `ls`
|
43 |
+
- To show current directory: `pwd`
|
44 |
+
- To display system info: `uname -a`
|
45 |
+
- To print something: `echo "Hello"`
|
46 |
+
""")
|
47 |
|
48 |
+
# A footer for better UI and personalized touch
|
49 |
st.markdown("""
|
50 |
<style>
|
51 |
+
footer {visibility: hidden;}
|
52 |
+
.css-18e3th9 {background-color: #34495e;}
|
53 |
+
h1 {color: #3498db;}
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
.stTextInput input {
|
55 |
+
border: 1px solid #2980b9;
|
56 |
+
background-color: #ecf0f1;
|
57 |
}
|
58 |
.stButton button {
|
59 |
+
background-color: #27ae60;
|
60 |
color: white;
|
61 |
+
font-size: 16px;
|
62 |
+
}
|
63 |
+
.stMarkdown h2, .stMarkdown h3 {
|
64 |
+
color: #2ecc71;
|
65 |
}
|
66 |
.stTextArea textarea {
|
67 |
border-color: #3498db;
|
68 |
}
|
69 |
+
.css-qbe2hs {
|
70 |
+
color: #f1c40f;
|
71 |
+
}
|
72 |
</style>
|
73 |
+
""", unsafe_allow_html=True)
|
74 |
+
|
75 |
+
# Custom footer text for a user-friendly experience
|
76 |
+
st.markdown("💡 **Tip**: Use simple commands and see the output instantly. Happy hacking!")
|