skanaujiya commited on
Commit
475d256
·
verified ·
1 Parent(s): 8b49023

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -29
app.py CHANGED
@@ -1,50 +1,76 @@
1
  import streamlit as st
2
  import subprocess
3
 
4
- # Streamlit UI layout
5
- st.title("Run Terminal Commands")
 
6
 
7
- # Create a text input field to enter the command
8
- command = st.text_input("Enter terminal command:")
 
 
 
 
 
 
 
9
 
10
  # Create a button to execute the command
11
  if st.button("Run Command"):
12
  if command:
13
- try:
14
- # Execute the terminal command and capture the output
15
- result = subprocess.run(command, shell=True, capture_output=True, text=True)
16
- # Display the output in the Streamlit app
17
- st.subheader("Command Output:")
18
- st.code(result.stdout)
19
- # Display errors, if any
20
- if result.stderr:
21
- st.error(result.stderr)
22
- except Exception as e:
23
- st.error(f"Error running command: {e}")
 
 
 
 
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
- visibility: hidden;
32
- }
33
- .css-18e3th9 {
34
- background-color: #2c3e50;
35
- }
36
- h1 {
37
- color: #3498db;
38
- }
39
  .stTextInput input {
40
- border: 1px solid #3498db;
 
41
  }
42
  .stButton button {
43
- background-color: #3498db;
44
  color: white;
 
 
 
 
45
  }
46
  .stTextArea textarea {
47
  border-color: #3498db;
48
  }
 
 
 
49
  </style>
50
- """, unsafe_allow_html=True)
 
 
 
 
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!")