spicysouvlaki commited on
Commit
efd3f06
1 Parent(s): 7d8b32c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import os
4
+ import sys
5
+ import subprocess
6
+ import shlex
7
+ from datetime import datetime
8
+
9
+ def save(s: subprocess.CompletedProcess):
10
+ if 'outputs' not in st.session_state:
11
+ st.session_state['outputs'] = []
12
+ st.session_state['outputs'].append({
13
+ 'returned_at': datetime.now(),
14
+ 'args': s.args,
15
+ 'stdout': str(s.stdout),
16
+ 'return_code': s.returncode,
17
+ 'stderr': str(s.stderr),
18
+ })
19
+
20
+ def list_files(startpath):
21
+ l = []
22
+ for root, dirs, files in os.walk(startpath):
23
+ level = root.replace(startpath, '').count(os.sep)
24
+ indent = ' ' * 4 * (level)
25
+ l.append('{}{}/'.format(indent, os.path.basename(root)))
26
+ subindent = ' ' * 4 * (level + 1)
27
+ for f in files:
28
+ l.append('{}{}'.format(subindent, f))
29
+ print('{}{}'.format(subindent, f))
30
+ return '\n'.join(l)
31
+
32
+ st.title("🌐 Streamlit Shell 🌐")
33
+ with st.expander("diagnostic"):
34
+ st.code(list_files(os.getcwd()))
35
+ st.code(f"sys.path: {sys.path}")
36
+ st.code(f"sys.argv: {sys.argv}" )
37
+ st.code(f"sys.executable: {sys.executable}")
38
+ st.code(f"sys.flags: {sys.flags}")
39
+
40
+ cmd_txt = st.text_input("command input: ", help='This will call a simple subprocess.run(<input>). The input is best effort parsed by shlex')
41
+ if cmd_txt and cmd_txt != "":
42
+ try:
43
+ s = subprocess.run(shlex.split(cmd_txt), capture_output=True)
44
+ save(s)
45
+ if s.returncode!= 0:
46
+ st.warning(f'non-zero return: {s.returncode}', icon="⚠️")
47
+ st.code(s.stdout.decode())
48
+ except Exception as inst:
49
+ st.error(inst)
50
+
51
+
52
+ if 'outputs' in st.session_state:
53
+ st.caption('hint: double click on long outputs')
54
+ st.dataframe(st.session_state['outputs'])