Update app.py
Browse files
app.py
CHANGED
@@ -1,84 +1,76 @@
|
|
1 |
import streamlit as st
|
2 |
import subprocess
|
3 |
|
4 |
-
#
|
5 |
-
st.
|
|
|
6 |
|
7 |
-
#
|
|
|
8 |
st.markdown("""
|
9 |
-
|
10 |
-
|
11 |
-
background-color: rgba(76, 175, 80, 0.2); /* Light green with transparency for output */
|
12 |
-
padding: 10px;
|
13 |
-
border-radius: 5px;
|
14 |
-
border: 1px solid rgba(76, 175, 80, 0.5); /* Semi-transparent green border */
|
15 |
-
}
|
16 |
-
.error {
|
17 |
-
background-color: rgba(244, 67, 54, 0.2); /* Light red with transparency for error */
|
18 |
-
padding: 10px;
|
19 |
-
border-radius: 5px;
|
20 |
-
border: 1px solid rgba(244, 67, 54, 0.5); /* Semi-transparent red border */
|
21 |
-
}
|
22 |
-
</style>
|
23 |
-
""", unsafe_allow_html=True)
|
24 |
-
|
25 |
-
# Main title
|
26 |
-
st.title("🎨 Advanced Terminal Emulator")
|
27 |
-
|
28 |
-
# Instructions and description
|
29 |
-
st.markdown("""
|
30 |
-
This enhanced terminal emulator lets you run commands and view outputs in a clean and modern interface.
|
31 |
-
You can access previous commands and see results in a well-organized manner.
|
32 |
""")
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
st.session_state.history = []
|
37 |
-
|
38 |
-
# Function to run the command and capture output
|
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 |
-
#
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
#
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
uploaded_file = st.file_uploader("Upload a file to process with command:", type=["txt", "csv"])
|
75 |
-
if uploaded_file:
|
76 |
-
file_content = uploaded_file.read().decode("utf-8")
|
77 |
-
st.subheader("Uploaded File Content")
|
78 |
-
st.text_area("File Content", value=file_content, height=200)
|
79 |
|
80 |
-
#
|
81 |
st.markdown("""
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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!")
|