Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -111,7 +111,7 @@ def join_game():
|
|
| 111 |
else:
|
| 112 |
st.error("Invalid Game ID. Please check and try again.")
|
| 113 |
|
| 114 |
-
# Function to start the game
|
| 115 |
def start_game(game_data):
|
| 116 |
topics = game_data['topics']
|
| 117 |
questions = game_data['questions']
|
|
@@ -171,102 +171,38 @@ def start_game(game_data):
|
|
| 171 |
|
| 172 |
st.success(f"Game Over! Your final score is {score}")
|
| 173 |
|
| 174 |
-
# Function to display
|
| 175 |
-
def
|
|
|
|
| 176 |
leaderboard_df = load_leaderboard()
|
|
|
|
| 177 |
|
| 178 |
-
st.subheader("
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
# First Place Winner - Celebration Animation
|
| 182 |
-
first_place = top_3.iloc[0] if not leaderboard_df.empty else None
|
| 183 |
-
if first_place is not None:
|
| 184 |
-
st.write(f"π {first_place['name']} - {first_place['score']} points! π {first_place['avatar']}")
|
| 185 |
-
st.markdown("<h3 style='color: gold;'>π Congratulations on First Place! π</h3>", unsafe_allow_html=True)
|
| 186 |
-
html_code = f"""
|
| 187 |
-
<div style="text-align: center;">
|
| 188 |
-
<h2>π Winner: {first_place['name']} π</h2>
|
| 189 |
-
<p>Score: {first_place['score']}</p>
|
| 190 |
-
<p>Avatar: {first_place['avatar']}</p>
|
| 191 |
-
</div>
|
| 192 |
-
<div id="balloon" style="position: absolute; top: 50%; left: 50%; animation: float 2s infinite;">
|
| 193 |
-
ππ
|
| 194 |
-
</div>
|
| 195 |
-
<style>
|
| 196 |
-
@keyframes float {{
|
| 197 |
-
0% {{ transform: translateY(0); }}
|
| 198 |
-
50% {{ transform: translateY(-50px); }}
|
| 199 |
-
100% {{ transform: translateY(0); }}
|
| 200 |
-
}}
|
| 201 |
-
</style>
|
| 202 |
-
"""
|
| 203 |
-
html(html_code)
|
| 204 |
-
|
| 205 |
-
# Second Place Winner - Celebration Animation
|
| 206 |
-
if len(top_3) > 1:
|
| 207 |
-
second_place = top_3.iloc[1]
|
| 208 |
-
st.write(f"π₯ {second_place['name']} - {second_place['score']} points! {second_place['avatar']}")
|
| 209 |
-
st.markdown("<h3 style='color: silver;'>π Congratulations on Second Place! π</h3>", unsafe_allow_html=True)
|
| 210 |
-
html_code = f"""
|
| 211 |
-
<div style="text-align: center;">
|
| 212 |
-
<h2>π₯ Runner-up: {second_place['name']} π₯</h2>
|
| 213 |
-
<p>Score: {second_place['score']}</p>
|
| 214 |
-
<p>Avatar: {second_place['avatar']}</p>
|
| 215 |
-
</div>
|
| 216 |
-
<div style="animation: clap 1s linear infinite;">
|
| 217 |
-
πππ
|
| 218 |
-
</div>
|
| 219 |
-
<style>
|
| 220 |
-
@keyframes clap {{
|
| 221 |
-
0% {{ transform: scale(1); }}
|
| 222 |
-
50% {{ transform: scale(1.2); }}
|
| 223 |
-
100% {{ transform: scale(1); }}
|
| 224 |
-
}}
|
| 225 |
-
</style>
|
| 226 |
-
"""
|
| 227 |
-
html(html_code)
|
| 228 |
|
| 229 |
-
#
|
| 230 |
-
if
|
| 231 |
-
|
| 232 |
-
st.
|
| 233 |
-
st.markdown("<h3 style='color: #cd7f32;'>π Nice Try on Third Place! π</h3>", unsafe_allow_html=True)
|
| 234 |
html_code = f"""
|
| 235 |
<div style="text-align: center;">
|
| 236 |
-
<h2>
|
| 237 |
-
<p>Score: {
|
| 238 |
-
<p>Avatar: {
|
| 239 |
</div>
|
| 240 |
-
<div style="
|
| 241 |
-
|
| 242 |
</div>
|
| 243 |
<style>
|
| 244 |
-
@keyframes
|
| 245 |
-
0% {{ transform:
|
| 246 |
-
|
| 247 |
-
100% {{ transform: rotate(0deg); }}
|
| 248 |
}}
|
| 249 |
</style>
|
| 250 |
"""
|
| 251 |
html(html_code)
|
| 252 |
|
| 253 |
-
# Pie chart for the distribution of player scores
|
| 254 |
-
fig = go.Figure(data=[go.Pie(labels=leaderboard_df['name'], values=leaderboard_df['score'], hole=0.3)])
|
| 255 |
-
fig.update_layout(title="Score Distribution")
|
| 256 |
-
st.plotly_chart(fig)
|
| 257 |
-
|
| 258 |
-
# Bar chart of leaderboard rankings
|
| 259 |
-
fig = px.bar(
|
| 260 |
-
leaderboard_df,
|
| 261 |
-
x='name',
|
| 262 |
-
y='score',
|
| 263 |
-
color='name',
|
| 264 |
-
title="Leaderboard",
|
| 265 |
-
labels={'name': 'Player', 'score': 'Score'},
|
| 266 |
-
hover_data=["avatar"]
|
| 267 |
-
)
|
| 268 |
-
st.plotly_chart(fig)
|
| 269 |
-
|
| 270 |
# Main function to handle Streamlit app
|
| 271 |
def main():
|
| 272 |
st.title('AI Quiz Game')
|
|
@@ -274,9 +210,7 @@ def main():
|
|
| 274 |
mode = st.sidebar.selectbox("Select Mode", ["Home", "Create Game", "Join Game", "Leaderboard"])
|
| 275 |
|
| 276 |
if mode == "Home":
|
| 277 |
-
|
| 278 |
-
st.write("You can create a new game, join an existing game, or check the leaderboard.")
|
| 279 |
-
display_dashboard()
|
| 280 |
|
| 281 |
elif mode == "Create Game":
|
| 282 |
create_game()
|
|
@@ -285,7 +219,7 @@ def main():
|
|
| 285 |
join_game()
|
| 286 |
|
| 287 |
elif mode == "Leaderboard":
|
| 288 |
-
|
| 289 |
|
| 290 |
if __name__ == "__main__":
|
| 291 |
main()
|
|
|
|
| 111 |
else:
|
| 112 |
st.error("Invalid Game ID. Please check and try again.")
|
| 113 |
|
| 114 |
+
# Function to start the game when all players have joined
|
| 115 |
def start_game(game_data):
|
| 116 |
topics = game_data['topics']
|
| 117 |
questions = game_data['questions']
|
|
|
|
| 171 |
|
| 172 |
st.success(f"Game Over! Your final score is {score}")
|
| 173 |
|
| 174 |
+
# Function to display recent players and cracker animations
|
| 175 |
+
def display_homepage():
|
| 176 |
+
# Display recent winners from the leaderboard file
|
| 177 |
leaderboard_df = load_leaderboard()
|
| 178 |
+
recent_winners = leaderboard_df.tail(5) # Show the most recent winners (up to 5)
|
| 179 |
|
| 180 |
+
st.subheader("Recent Winners")
|
| 181 |
+
for index, winner in recent_winners.iterrows():
|
| 182 |
+
st.write(f"{winner['name']} - {winner['score']} points - Avatar: {winner['avatar']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
+
# Celebration for the first winner with cracker animation
|
| 185 |
+
first_winner = recent_winners.iloc[-1] if not recent_winners.empty else None
|
| 186 |
+
if first_winner is not None:
|
| 187 |
+
st.markdown("<h3 style='color: gold;'>π Congratulations to the First Winner! π</h3>", unsafe_allow_html=True)
|
|
|
|
| 188 |
html_code = f"""
|
| 189 |
<div style="text-align: center;">
|
| 190 |
+
<h2>π {first_winner['name']} π</h2>
|
| 191 |
+
<p>Score: {first_winner['score']}</p>
|
| 192 |
+
<p>Avatar: {first_winner['avatar']}</p>
|
| 193 |
</div>
|
| 194 |
+
<div id="fireworks" style="position: absolute; top: 50%; left: 50%; animation: fireworks 2s infinite;">
|
| 195 |
+
ππ
|
| 196 |
</div>
|
| 197 |
<style>
|
| 198 |
+
@keyframes fireworks {{
|
| 199 |
+
0% {{ transform: scale(0); opacity: 1; }}
|
| 200 |
+
100% {{ transform: scale(3); opacity: 0; }}
|
|
|
|
| 201 |
}}
|
| 202 |
</style>
|
| 203 |
"""
|
| 204 |
html(html_code)
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
# Main function to handle Streamlit app
|
| 207 |
def main():
|
| 208 |
st.title('AI Quiz Game')
|
|
|
|
| 210 |
mode = st.sidebar.selectbox("Select Mode", ["Home", "Create Game", "Join Game", "Leaderboard"])
|
| 211 |
|
| 212 |
if mode == "Home":
|
| 213 |
+
display_homepage()
|
|
|
|
|
|
|
| 214 |
|
| 215 |
elif mode == "Create Game":
|
| 216 |
create_game()
|
|
|
|
| 219 |
join_game()
|
| 220 |
|
| 221 |
elif mode == "Leaderboard":
|
| 222 |
+
display_homepage()
|
| 223 |
|
| 224 |
if __name__ == "__main__":
|
| 225 |
main()
|