File size: 1,169 Bytes
9f918c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import streamlit as st
import os


os.makedirs('/tmp', exist_ok=True)
os.makedirs('/tmp/data', exist_ok=True)
st.title("📁 Document Upload & Download App")

# File uploader
uploaded_files = st.file_uploader("Upload documents", type=["pdf", "docx", "txt", "xlsx"], accept_multiple_files=True)

if uploaded_files:
    for file in uploaded_files:
        file_path = os.path.join('/tmp/data', file.name)
        with open(file_path, "wb") as f:
            f.write(file.getbuffer())
        st.success(f"Saved: {file.name}")

st.markdown("---")
st.subheader("📂 Download Saved Files")

saved_files = os.listdir("/tmp/data")
print(saved_files)

print("done fetching")
if saved_files:
    for filename in saved_files:
        print(filename)
        file_path = os.path.join('/tmp/data', filename)
        print(file_path)
        with open(file_path, "rb") as f:
            st.download_button(
                label=f"⬇️ Download {filename}",
                data=f,
                file_name=filename,
                mime="application/octet-stream",
                use_container_width=True
            )
else:
    st.info("No files available for download.")