Spaces:
Sleeping
Sleeping
Update app.py
Browse files//LOG_ 111524_b
aaaaaaaaa
//endlog
/commit
app.py
CHANGED
|
@@ -27,36 +27,7 @@ class WheelOfNames:
|
|
| 27 |
st.session_state.groups_text = ""
|
| 28 |
st.session_state.result_label = ""
|
| 29 |
|
| 30 |
-
|
| 31 |
-
import random
|
| 32 |
-
|
| 33 |
-
class WheelOfNames:
|
| 34 |
-
def __init__(self, names):
|
| 35 |
-
self.names = names
|
| 36 |
-
|
| 37 |
-
def add_name(self, name):
|
| 38 |
-
if name.strip():
|
| 39 |
-
self.names.append(name.strip())
|
| 40 |
-
st.session_state.name_list_text = "\n".join(self.names)
|
| 41 |
-
|
| 42 |
-
def upload_file(self):
|
| 43 |
-
uploaded_file = st.file_uploader("Upload a text file containing names", type=["txt"])
|
| 44 |
-
if uploaded_file:
|
| 45 |
-
self.names.extend([line.decode().strip() for line in uploaded_file])
|
| 46 |
-
st.session_state.name_list_text = "\n".join(self.names)
|
| 47 |
-
|
| 48 |
-
def save_file(self):
|
| 49 |
-
if self.names:
|
| 50 |
-
return "\n".join(self.names)
|
| 51 |
-
return None
|
| 52 |
-
|
| 53 |
-
def clear_names(self):
|
| 54 |
-
self.names = []
|
| 55 |
-
st.session_state.name_list_text = ""
|
| 56 |
-
st.session_state.groups_text = ""
|
| 57 |
-
st.session_state.result_label = ""
|
| 58 |
-
|
| 59 |
-
def sort_into_groups(self):
|
| 60 |
group_size = st.session_state.group_size_var
|
| 61 |
if not group_size.isdigit():
|
| 62 |
st.error("Please enter a valid group size.")
|
|
@@ -76,22 +47,17 @@ class WheelOfNames:
|
|
| 76 |
random.shuffle(names_copy)
|
| 77 |
|
| 78 |
groups = []
|
| 79 |
-
while
|
| 80 |
group = names_copy[:group_size]
|
| 81 |
groups.append(group)
|
| 82 |
names_copy = names_copy[group_size:]
|
| 83 |
|
| 84 |
-
# If there are remaining names, add them as a group
|
| 85 |
-
if names_copy:
|
| 86 |
-
groups.append(names_copy)
|
| 87 |
-
|
| 88 |
# Join groups into a single string
|
| 89 |
groups_text = "\n".join(f"Group {i}: {', '.join(group)}" for i, group in enumerate(groups, 1))
|
| 90 |
st.session_state.groups_text = groups_text
|
| 91 |
|
| 92 |
-
# Optionally remove used names from the original list
|
| 93 |
-
remove_used_names = st.session_state.remove_used_names
|
| 94 |
if remove_used_names:
|
|
|
|
| 95 |
used_names = [name for group in groups for name in group]
|
| 96 |
self.names = [name for name in self.names if name not in used_names]
|
| 97 |
st.session_state.name_list_text = "\n".join(self.names)
|
|
@@ -111,91 +77,6 @@ class WheelOfNames:
|
|
| 111 |
st.session_state.name_list_text = "\n".join(self.names)
|
| 112 |
st.session_state.result_label = ""
|
| 113 |
|
| 114 |
-
def main():
|
| 115 |
-
st.title("Wheel of Names")
|
| 116 |
-
|
| 117 |
-
if 'names' not in st.session_state:
|
| 118 |
-
st.session_state.names = []
|
| 119 |
-
if 'name_list_text' not in st.session_state:
|
| 120 |
-
st.session_state.name_list_text = ""
|
| 121 |
-
if 'groups_text' not in st.session_state:
|
| 122 |
-
st.session_state.groups_text = ""
|
| 123 |
-
if'result_label' not in st.session_state:
|
| 124 |
-
st.session_state.result_label = ""
|
| 125 |
-
if 'group_size_var' not in st.session_state:
|
| 126 |
-
st.session_state.group_size_var = "2"
|
| 127 |
-
if'remove_used_names' not in st.session_state:
|
| 128 |
-
st.session_state.remove_used_names = False
|
| 129 |
-
|
| 130 |
-
wheel = WheelOfNames(st.session_state.names)
|
| 131 |
-
|
| 132 |
-
with st.sidebar:
|
| 133 |
-
st.subheader("Names")
|
| 134 |
-
name_entry = st.text_input("Enter a name")
|
| 135 |
-
if st.button("Add Name"):
|
| 136 |
-
wheel.add_name(name_entry)
|
| 137 |
-
st.session_state.names = wheel.names
|
| 138 |
-
|
| 139 |
-
wheel.upload_file()
|
| 140 |
-
|
| 141 |
-
if st.button("Save Names to File"):
|
| 142 |
-
names_data = wheel.save_file()
|
| 143 |
-
if names_data:
|
| 144 |
-
st.download_button(
|
| 145 |
-
label="Download Names",
|
| 146 |
-
data=names_data,
|
| 147 |
-
file_name="names.txt",
|
| 148 |
-
mime="text/plain"
|
| 149 |
-
)
|
| 150 |
-
else:
|
| 151 |
-
st.error("No names to save.")
|
| 152 |
-
|
| 153 |
-
if st.button("Clear Names"):
|
| 154 |
-
wheel.clear_names()
|
| 155 |
-
st.session_state.names = wheel.names
|
| 156 |
-
|
| 157 |
-
st.subheader("Names List")
|
| 158 |
-
st.text_area("Names List", value=st.session_state.name_list_text, height=110)
|
| 159 |
-
|
| 160 |
-
st.subheader("Group Size")
|
| 161 |
-
group_size_var = st.number_input("Enter group size", min_value=1, value=int(st.session_state.group_size_var))
|
| 162 |
-
st.session_state.group_size_var = str(group_size_var)
|
| 163 |
-
|
| 164 |
-
st.subheader("Sorting Options")
|
| 165 |
-
remove_used_names = st.checkbox("Remove Used Names After Sorting", value=st.session_state.remove_used_names)
|
| 166 |
-
st.session_state.remove_used_names = remove_used_names
|
| 167 |
-
|
| 168 |
-
if st.button("Sort into Groups"):
|
| 169 |
-
wheel.sort_into_groups()
|
| 170 |
-
|
| 171 |
-
st.subheader("Groups")
|
| 172 |
-
st.text_area("Groups List", value=st.session_state.groups_text, height=150)
|
| 173 |
-
|
| 174 |
-
st.subheader("Spin the Wheel")
|
| 175 |
-
if st.button("Spin"):
|
| 176 |
-
wheel.spin_wheel()
|
| 177 |
-
|
| 178 |
-
st.subheader("Result")
|
| 179 |
-
st.markdown(f"<h1 style='text-align: center;'>{st.session_state.result_label}</h1>", unsafe_allow_html=True)
|
| 180 |
-
|
| 181 |
-
if __name__ == "__main__":
|
| 182 |
-
main()
|
| 183 |
-
|
| 184 |
-
def spin_wheel(self):
|
| 185 |
-
if not self.names:
|
| 186 |
-
st.error("Please add or upload names first")
|
| 187 |
-
return
|
| 188 |
-
|
| 189 |
-
winning_name = random.choice(self.names)
|
| 190 |
-
st.session_state.result_label = winning_name
|
| 191 |
-
|
| 192 |
-
# Ask user if they want to remove the name
|
| 193 |
-
remove_name = st.button("Remove Selected Name", key="remove_name_button")
|
| 194 |
-
if remove_name:
|
| 195 |
-
self.names.remove(winning_name)
|
| 196 |
-
st.session_state.name_list_text = "\n".join(self.names)
|
| 197 |
-
st.session_state.result_label = ""
|
| 198 |
-
|
| 199 |
def main():
|
| 200 |
st.title("Wheel of Names")
|
| 201 |
|
|
@@ -251,7 +132,7 @@ def main():
|
|
| 251 |
st.session_state.remove_used_names = remove_used_names
|
| 252 |
|
| 253 |
if st.button("Sort into Groups"):
|
| 254 |
-
wheel.sort_into_groups()
|
| 255 |
|
| 256 |
st.subheader("Groups")
|
| 257 |
st.text_area("Groups List", value=st.session_state.groups_text, height=150)
|
|
|
|
| 27 |
st.session_state.groups_text = ""
|
| 28 |
st.session_state.result_label = ""
|
| 29 |
|
| 30 |
+
def sort_into_groups(self, remove_used_names):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
group_size = st.session_state.group_size_var
|
| 32 |
if not group_size.isdigit():
|
| 33 |
st.error("Please enter a valid group size.")
|
|
|
|
| 47 |
random.shuffle(names_copy)
|
| 48 |
|
| 49 |
groups = []
|
| 50 |
+
while names_copy:
|
| 51 |
group = names_copy[:group_size]
|
| 52 |
groups.append(group)
|
| 53 |
names_copy = names_copy[group_size:]
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# Join groups into a single string
|
| 56 |
groups_text = "\n".join(f"Group {i}: {', '.join(group)}" for i, group in enumerate(groups, 1))
|
| 57 |
st.session_state.groups_text = groups_text
|
| 58 |
|
|
|
|
|
|
|
| 59 |
if remove_used_names:
|
| 60 |
+
# Remove used names from the original list
|
| 61 |
used_names = [name for group in groups for name in group]
|
| 62 |
self.names = [name for name in self.names if name not in used_names]
|
| 63 |
st.session_state.name_list_text = "\n".join(self.names)
|
|
|
|
| 77 |
st.session_state.name_list_text = "\n".join(self.names)
|
| 78 |
st.session_state.result_label = ""
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
def main():
|
| 81 |
st.title("Wheel of Names")
|
| 82 |
|
|
|
|
| 132 |
st.session_state.remove_used_names = remove_used_names
|
| 133 |
|
| 134 |
if st.button("Sort into Groups"):
|
| 135 |
+
wheel.sort_into_groups(remove_used_names)
|
| 136 |
|
| 137 |
st.subheader("Groups")
|
| 138 |
st.text_area("Groups List", value=st.session_state.groups_text, height=150)
|