File size: 2,968 Bytes
1fa1bcc
d158e71
1fa1bcc
d158e71
1fa1bcc
 
d158e71
1fa1bcc
 
 
 
 
 
 
3c89625
1fa1bcc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d158e71
 
 
 
 
 
 
 
 
 
 
 
1fa1bcc
d158e71
 
 
1fa1bcc
 
 
 
 
 
 
 
 
3c89625
d158e71
 
1fa1bcc
 
d158e71
1fa1bcc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7936ee
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
import os
import streamlit as st

def list_files():
    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)
    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")

# Sidebar
with st.sidebar:
    st.subheader("Download Files")
    file_list = list_files()
    if file_list:
        for file in file_list:
            if st.button(file):
                file_path = os.path.join(os.getcwd(), file[2:])
                st.markdown(f"### {file}")
                st.markdown(f"[Download]({file_path})")
    else:
        st.markdown("No .csv or .txt files found in the current directory.")

# Main content
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")

if listFiles:
    fileContent = "\n".join(list_files())
    st.text_area("File Content", fileContent)
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 πŸ‘πŸ§ πŸš€ 
""")