File size: 3,855 Bytes
ca8935b
7d7cace
0692ff6
7d294f3
 
0692ff6
eb42ed9
7d294f3
eb42ed9
c3c4747
 
 
 
 
 
 
 
 
 
 
 
fb2c72e
eb42ed9
 
00e8820
 
eb42ed9
 
00e8820
538187a
 
 
00e8820
1dc15ce
 
381fb97
1dc15ce
 
 
 
 
 
 
 
 
eb42ed9
fb2c72e
0441490
c3c4747
 
de1ba67
 
 
 
 
0692ff6
a526566
0692ff6
 
 
7d294f3
 
 
 
 
 
5d6578f
35b583e
 
 
 
 
 
 
 
 
 
 
 
 
848db73
c3c4747
 
 
35b583e
5d6578f
35b583e
 
 
 
 
 
 
 
 
 
 
 
 
374569e
 
 
35b583e
5d6578f
35b583e
 
 
 
 
 
 
 
 
 
 
 
 
381fb97
 
 
35b583e
5d6578f
35b583e
 
 
 
 
 
 
 
 
 
 
 
 
5450f7d
a526566
0692ff6
 
ca8935b
eb42ed9
c892be7
 
55c2f3f
 
 
c892be7
 
ccb54a0
 
 
 
19dad51
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import streamlit as st
import os
from streamlit_extras.stylable_container import stylable_container
from PIL import Image


# Variables used Globally
path = "/data"  #preset path for hugging face spaces for persistent storage and cannot be changed

# Application Functions
# File Loader
@st.dialog("Upload a File")
def upload_file():
    uploaded_file = st.file_uploader("Choose a file")
    if uploaded_file is not None:
        file_details = {"FileName":uploaded_file.name,"FileType":uploaded_file.type}
        st.write(file_details)
        with open(os.path.join(path,uploaded_file.name),"wb") as f: 
           f.write(uploaded_file.getbuffer())         
           st.success("Saved File")

# File Delete
@st.dialog("Delete a File")
def delete_file():
    # List all files in directory and subdirectories as buttons
    
    for root, dirs, file_names in os.walk(path):
        for file_name in file_names:
            if st.button(file_name):
                os.remove(os.path.join(path,file_name))
                st.success("Removed File")
                st.rerun()
       
# File View
@st.dialog("Files used by AI")
def view_file():
    # List all files in directory and subdirectories
    files = []
    for root, dirs, file_names in os.walk(path):
        for file_name in file_names:
            files.append(file_name)
   
    st.write(files)
    if st.button("Close"):
       st.rerun()
        
 
          



Logo_column, space_column, upload_column, delete_column, browse_column, recycle_column  = st.columns(6)



st.markdown(
    '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"/> ',
    unsafe_allow_html=True,
)



with logo_column:
    image = Image.open(os.path.join(path,'spaces-hot-dog-streamlit.png')
    st.image(image, caption='CRIStine')
    
with upload_column:
    with stylable_container(
        key="upload_button",
        css_styles=r"""
            button p:before {
                font-family: 'Font Awesome 5 Free';
                content: '\f574';
                display: inline-block;
                padding-right: 3px;
                vertical-align: middle;
                font-weight: 900;
            }
            """,
    ):
        if st.button("Upload",  key='upload'):
            upload_file()
 
    

with delete_column:
    with stylable_container(
        key="delete_button",
        css_styles=r"""
            button p:before {
                font-family: 'Font Awesome 5 Free';
                content: '\f1c3';
                display: inline-block;
                padding-right: 3px;
                vertical-align: middle;
                font-weight: 900;
            }
            """,
    ):
        if st.button("Delete",  key='delete'):
            delete_file()
             

with browse_column:
    with stylable_container(
        key="view_button",
        css_styles=r"""
            button p:before {
                font-family: 'Font Awesome 5 Free';
                content: '\f07c';
                display: inline-block;
                padding-right: 3px;
                vertical-align: middle;
                font-weight: 900;
            }
            """,
    ):
        if st.button("View",  key='view'):
            view_file()
            

with recycle_column:
    with stylable_container(
        key="recycle_button",
        css_styles=r"""
            button p:before {
                font-family: 'Font Awesome 5 Free';
                content: '\f1b8';
                display: inline-block;
                padding-right: 3px;
                vertical-align: middle;
                font-weight: 900;
            }
            """,
    ):
        st.button("Recycle",  key='recycle')
    
    
    




# Main app
st.write("Click the button to open the file upload dialog.")