Spaces:
Sleeping
Sleeping
Update app.py
Browse files//LOG_ 111424_d
Fix spinning/sorting issues
//endlog
/commit
app.py
CHANGED
|
@@ -44,13 +44,13 @@ class WheelOfNames:
|
|
| 44 |
|
| 45 |
random.shuffle(self.names)
|
| 46 |
groups = []
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
groups.append(group)
|
| 50 |
-
|
| 51 |
|
| 52 |
st.session_state.groups_text = "\n".join(f"Group {i}: {', '.join(group)}" for i, group in enumerate(groups, 1))
|
| 53 |
-
st.session_state.name_list_text = "\n".join(self.names)
|
| 54 |
|
| 55 |
def spin_wheel(self):
|
| 56 |
if not self.names:
|
|
@@ -59,8 +59,13 @@ class WheelOfNames:
|
|
| 59 |
|
| 60 |
winning_name = random.choice(self.names)
|
| 61 |
st.session_state.result_label = winning_name
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
def main():
|
| 66 |
st.title("Wheel of Names")
|
|
@@ -104,7 +109,7 @@ def main():
|
|
| 104 |
st.session_state.names = wheel.names
|
| 105 |
|
| 106 |
st.subheader("Names List")
|
| 107 |
-
st.text_area("Names List", value=st.session_state.name_list_text, height=
|
| 108 |
|
| 109 |
st.subheader("Group Size")
|
| 110 |
group_size_var = st.number_input("Enter group size", min_value=1, value=int(st.session_state.group_size_var))
|
|
@@ -112,7 +117,6 @@ def main():
|
|
| 112 |
|
| 113 |
if st.button("Sort into Groups"):
|
| 114 |
wheel.sort_into_groups()
|
| 115 |
-
st.session_state.names = wheel.names
|
| 116 |
|
| 117 |
st.subheader("Groups")
|
| 118 |
st.text_area("Groups List", value=st.session_state.groups_text, height=150)
|
|
@@ -120,7 +124,6 @@ def main():
|
|
| 120 |
st.subheader("Spin the Wheel")
|
| 121 |
if st.button("Spin"):
|
| 122 |
wheel.spin_wheel()
|
| 123 |
-
st.session_state.names = wheel.names
|
| 124 |
|
| 125 |
st.subheader("Result")
|
| 126 |
st.markdown(f"<h1 style='text-align: center;'>{st.session_state.result_label}</h1>", unsafe_allow_html=True)
|
|
|
|
| 44 |
|
| 45 |
random.shuffle(self.names)
|
| 46 |
groups = []
|
| 47 |
+
names_copy = self.names.copy()
|
| 48 |
+
while names_copy:
|
| 49 |
+
group = names_copy[:group_size]
|
| 50 |
groups.append(group)
|
| 51 |
+
names_copy = names_copy[group_size:]
|
| 52 |
|
| 53 |
st.session_state.groups_text = "\n".join(f"Group {i}: {', '.join(group)}" for i, group in enumerate(groups, 1))
|
|
|
|
| 54 |
|
| 55 |
def spin_wheel(self):
|
| 56 |
if not self.names:
|
|
|
|
| 59 |
|
| 60 |
winning_name = random.choice(self.names)
|
| 61 |
st.session_state.result_label = winning_name
|
| 62 |
+
|
| 63 |
+
# Ask user if they want to remove the name
|
| 64 |
+
remove_name = st.button("Remove Selected Name")
|
| 65 |
+
if remove_name:
|
| 66 |
+
self.names.remove(winning_name)
|
| 67 |
+
st.session_state.name_list_text = "\n".join(self.names)
|
| 68 |
+
st.session_state.result_label = ""
|
| 69 |
|
| 70 |
def main():
|
| 71 |
st.title("Wheel of Names")
|
|
|
|
| 109 |
st.session_state.names = wheel.names
|
| 110 |
|
| 111 |
st.subheader("Names List")
|
| 112 |
+
st.text_area("Names List", value=st.session_state.name_list_text, height=110)
|
| 113 |
|
| 114 |
st.subheader("Group Size")
|
| 115 |
group_size_var = st.number_input("Enter group size", min_value=1, value=int(st.session_state.group_size_var))
|
|
|
|
| 117 |
|
| 118 |
if st.button("Sort into Groups"):
|
| 119 |
wheel.sort_into_groups()
|
|
|
|
| 120 |
|
| 121 |
st.subheader("Groups")
|
| 122 |
st.text_area("Groups List", value=st.session_state.groups_text, height=150)
|
|
|
|
| 124 |
st.subheader("Spin the Wheel")
|
| 125 |
if st.button("Spin"):
|
| 126 |
wheel.spin_wheel()
|
|
|
|
| 127 |
|
| 128 |
st.subheader("Result")
|
| 129 |
st.markdown(f"<h1 style='text-align: center;'>{st.session_state.result_label}</h1>", unsafe_allow_html=True)
|