Meteorama commited on
Commit
d1ac52b
·
verified ·
1 Parent(s): 9eec85a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -10
app.py CHANGED
@@ -1,35 +1,69 @@
1
  import streamlit as st
2
  import os
3
  from glob import glob
 
4
 
 
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- st.title("UPLOAD ANY FILE..!!")
 
 
 
 
 
8
 
9
- uploaded_file = st.file_uploader("Choose to upload")
10
 
11
- if uploaded_file is not None:
12
- bytes_data = uploaded_file.read()
 
13
 
14
- with open(os.path.join(os.getcwd(),"files",uploaded_file.name),"wb") as f:
15
- f.write(uploaded_file.getbuffer())
16
- st.success("Uploaded..!!")
 
 
 
 
17
 
18
  st.header("Available Files")
19
 
20
  files_list = glob(os.path.join(os.getcwd(),"files","*.*"))
21
 
 
 
22
  for file in files_list:
23
  with open(file, 'rb') as f:
24
- st.download_button('Download {}'.format(os.path.basename(file)), f, file_name=os.path.basename(file))
25
 
26
 
 
 
27
  if st.button("Delete All Files"):
28
  files_list = glob(os.path.join(os.getcwd(),"files","*.*"))
29
  for f in files_list:
 
 
30
  if(os.path.exists(f)):
31
  os.remove(f)
32
- st.info("All files deleted!!! Refresh the page to see changes.")
33
 
 
34
 
35
- st.caption("Meteo Rama")
 
1
  import streamlit as st
2
  import os
3
  from glob import glob
4
+ import time
5
 
6
+ st.set_page_config(initial_sidebar_state="collapsed", page_title='Quick File Share')
7
 
8
+ #Hide header style
9
+ hide_st_style = """
10
+ <style>
11
+ #MainMenu {visibility: hidden;},
12
+ footer {visibility: hidden;},
13
+ header {visibility: hidden;}
14
+ [data-testid="collapsedControl"] {
15
+ display: none
16
+ }
17
+ [data-testid="stHeader"] {
18
+ display: none
19
+ }
20
+ .st-emotion-cache-1y4p8pa {
21
+ width: 100%;
22
+ padding: 1rem 1rem 10rem;
23
+ max-width: 46rem;
24
+ }
25
 
26
+ [data-testid="stButton"]{
27
+ margin-top: 5px;
28
+ }
29
+ }
30
+ </style>
31
+ """
32
 
33
+ st.markdown(hide_st_style, unsafe_allow_html = True)
34
 
35
+ st.title("Quick File Share")
36
+
37
+ uploaded_file = st.file_uploader("Choose a file to upload", accept_multiple_files=True)
38
 
39
+
40
+ if uploaded_file is not None:
41
+ for u_file in uploaded_file:
42
+ bytes_data = u_file.read()
43
+ with open(os.path.join(os.getcwd(),"files",u_file.name.replace(" ", "_")),"wb") as f:
44
+ f.write(u_file.getbuffer())
45
+ st.success("File Uploaded")
46
 
47
  st.header("Available Files")
48
 
49
  files_list = glob(os.path.join(os.getcwd(),"files","*.*"))
50
 
51
+ table_html = "<table border=1 width=100%><th>FileName</th><th>Uploaded On</th><th>Show</th>"
52
+
53
  for file in files_list:
54
  with open(file, 'rb') as f:
55
+ table_html = table_html + f"<tr><td>{os.path.basename(file)}</td><td>{time.ctime(os.path.getctime(file))}</td><td><a href='Show_File?name={os.path.basename(file)}'>Show</a></td></tr>"
56
 
57
 
58
+ st.markdown(table_html + "</table>", unsafe_allow_html=True)
59
+
60
  if st.button("Delete All Files"):
61
  files_list = glob(os.path.join(os.getcwd(),"files","*.*"))
62
  for f in files_list:
63
+
64
+
65
  if(os.path.exists(f)):
66
  os.remove(f)
 
67
 
68
+ st.info("All files deleted!!! Refresh the page to see changes.")
69