skanaujiya commited on
Commit
0682a81
·
verified ·
1 Parent(s): 36d9343

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -21
app.py CHANGED
@@ -39,24 +39,20 @@ 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
- 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])
50
 
51
- # Command history display in the first column
52
  with col1:
53
- st.subheader("Command History")
54
- for cmd in reversed(st.session_state.history):
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"):
62
  if command:
@@ -67,13 +63,12 @@ with col2:
67
  else:
68
  st.warning("Please enter a command to run.")
69
 
70
- # Output display in the third column
71
- with col3:
72
- st.subheader("Output:")
73
- if 'output' in st.session_state and st.session_state.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.markdown(f'<div class="error">{st.session_state.error}</div>', unsafe_allow_html=True)
77
 
78
  # Optional file upload (if needed)
79
  uploaded_file = st.file_uploader("Upload a file to process with command:", type=["txt", "csv"])
 
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
+ # Command input and button in the first column
55
  with col1:
 
 
 
 
 
 
 
56
  command = st.text_area("Enter terminal command", placeholder="e.g., ls, pwd, echo 'Hello World'", height=100)
57
  if st.button("Run Command"):
58
  if command:
 
63
  else:
64
  st.warning("Please enter a command to run.")
65
 
66
+ # Command history display in the second column
67
+ with col2:
68
+ st.subheader("Command History")
69
+ for cmd in reversed(st.session_state.history):
70
+ if st.button(f"Run: {cmd}", key=cmd):
71
+ run_command(cmd)
 
72
 
73
  # Optional file upload (if needed)
74
  uploaded_file = st.file_uploader("Upload a file to process with command:", type=["txt", "csv"])