TestChat / app.py
w3robotics's picture
Update app.py
122cdab verified
raw
history blame
3.81 kB
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 goes below here -