Spaces:
Runtime error
Runtime error
File size: 3,200 Bytes
1fa1bcc 3c89625 1fa1bcc 3c89625 1fa1bcc 3c89625 1fa1bcc 3c89625 1fa1bcc d6a6ef4 63466bc |
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 |
import streamlit as st
import os
def list_files(file_path=''):
icon_csv = "π "
icon_txt = "π "
current_directory = os.getcwd()
file_list = []
for filename in os.listdir(current_directory):
if filename.endswith(".csv"):
file_list.append(icon_csv + filename)
elif filename.endswith(".txt"):
file_list.append(icon_txt + filename)
file_list.sort(reverse=True)
return file_list
def read_file(file_path):
try:
with open(file_path, "r") as file:
contents = file.read()
return f"{contents}"
except FileNotFoundError:
return "File not found."
def delete_file(file_path):
try:
os.remove(file_path)
return f"{file_path} has been deleted."
except FileNotFoundError:
return "File not found."
def write_file(file_path, content):
try:
with open(file_path, "w") as file:
file.write(content)
return f"Successfully written to {file_path}."
except:
return "Error occurred while writing to file."
def append_file(file_path, content):
try:
with open(file_path, "a") as file:
file.write(content)
return f"Successfully appended to {file_path}."
except:
return "Error occurred while appending to file."
st.set_page_config(layout='wide')
st.title("AI Feedback Memory System for Smart Communities")
fileName = st.text_input("Filename")
fileContent = st.text_area("File Content")
completedMessage_placeholder = st.empty()
col1, col2, col3, col4, col5 = st.columns(5)
listFiles = col1.button("π List File(s)")
readFile = col2.button("π Read File")
saveFile = col3.button("πΎ Save File")
deleteFile = col4.button("ποΈ Delete File")
appendFile = col5.button("β Append File")
files_list_sidebar = st.sidebar.selectbox("Files", options=list_files(), key="file_list")
if files_list_sidebar:
fileContent = read_file(files_list_sidebar[2:])
st.text_area("File Content", fileContent)
if listFiles:
file_list = list_files(fileName)
st.text_area("File Content", "\n".join(file_list))
st.sidebar.selectbox("Files", options=file_list, key="file_list_updated")
elif readFile:
fileContent = read_file(fileName)
st.text_area("File Content", fileContent)
elif saveFile:
completedMessage = write_file(fileName, fileContent)
completedMessage_placeholder.text(completedMessage)
elif deleteFile:
completedMessage = delete_file(fileName)
completedMessage_placeholder.text(completedMessage)
elif appendFile:
completedMessage = append_file(fileName, fileContent)
completedMessage_placeholder.text(completedMessage)
st.markdown("""
π‘π§ π
π€ππ
ππ€£π
π―π¨βπΌπ¬
πππ
π±π»π
The new π€ AI Feedback Memory System for Smart Communities π‘π§ π
is here to help you remember important details about the people and places in your community.
Input information and the system will use advanced algorithms ππ to help you remember key details. Plus, it's fun! π€£ππ.
Available now on Hugging Face! π±π»π. Get ready to use your new superpower to remember.
""") |