file_share / app.py
Meteorama's picture
Update app.py
f3f6822 verified
import streamlit as st
import os
from glob import glob
import time
st.set_page_config(initial_sidebar_state="collapsed", page_title='File Upload')
#Hide header style
hide_st_style = """
<style>
#MainMenu {visibility: hidden;},
footer {visibility: hidden;},
header {visibility: hidden;}
[data-testid="collapsedControl"] {
display: none
}
[data-testid="stHeader"] {
display: none
}
.st-emotion-cache-1y4p8pa {
width: 100%;
padding: 1rem 1rem 10rem;
max-width: 46rem;
}
[data-testid="stButton"]{
margin-top: 5px;
}
}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html = True)
st.title("File Upload")
uploaded_file = st.file_uploader("Choose a file to upload", accept_multiple_files=True)
if uploaded_file is not None:
for u_file in uploaded_file:
bytes_data = u_file.read()
with open(os.path.join(os.getcwd(),"files",u_file.name.replace(" ", "_")),"wb") as f:
f.write(u_file.getbuffer())
st.success("File Uploaded")
st.header("Available Files")
st.caption("Meteo Rama")
files_list = glob(os.path.join(os.getcwd(),"files","*.*"))
table_html = "<table border=1 width=100%><th>FileName</th><th>Uploaded On</th><th>Show</th>"
for file in files_list:
with open(file, 'rb') as f:
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>"
st.markdown(table_html + "</table>", unsafe_allow_html=True)
if st.button("Delete All Files"):
files_list = glob(os.path.join(os.getcwd(),"files","*.*"))
for f in files_list:
if(os.path.exists(f)):
os.remove(f)
st.info("All files deleted!!! Refresh the page to see changes.")