-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimmutable_words_app.py
More file actions
60 lines (52 loc) · 1.76 KB
/
immutable_words_app.py
File metadata and controls
60 lines (52 loc) · 1.76 KB
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
import streamlit as st
import json
def load_words():
try:
with open('immutable_words.json', 'r') as f:
data = json.load(f)
return data['words']
except FileNotFoundError:
# If file not found, return an empty list
return []
def save_words(words):
with open('immutable_words.json', 'w') as f:
json.dump({"words": words}, f)
def main():
st.title("Manage Immutable Words")
words = load_words()
st.markdown("---")
st.subheader("Add New Word")
new_word = st.text_input("Enter New Word:")
if st.button("Add"):
if new_word.strip() != "":
words.append(new_word)
save_words(words)
st.success("Word added successfully.")
else:
st.error("Please enter a valid word.")
st.markdown("---")
st.subheader("Update or Delete Existing Words")
if not words:
st.write("No words added yet.")
else:
selected_word = st.selectbox("Select Word:", words)
new_word = st.text_input("If Updating, Update here:", value=selected_word)
col1, col2 = st.columns(2)
with col1:
if st.button("Delete"):
words.remove(selected_word)
save_words(words)
st.success("Word deleted successfully.")
with col2:
if st.button("Update"):
if new_word.strip() != "":
index = words.index(selected_word)
words[index] = new_word
save_words(words)
st.success("Word updated successfully.")
else:
st.error("Please enter a valid word.")
st.markdown("---")
st.write("Current Words:", words)
if __name__ == "__main__":
main()