Spaces:
Running
Running
Update app.py (#8)
Browse files- Update app.py (cad7644d9b8a0c242f5af20a823a079e82926c4b)
app.py
CHANGED
|
@@ -27,7 +27,6 @@ questions_db = {
|
|
| 27 |
("Which river flows through Egypt?", ["Nile", "Amazon", "Ganges", "Yangtze"], "Nile"),
|
| 28 |
("What is the capital of Japan?", ["Tokyo", "Kyoto", "Osaka", "Sapporo"], "Tokyo"),
|
| 29 |
("Which is the smallest country in the world?", ["Monaco", "Vatican City", "San Marino", "Liechtenstein"], "Vatican City"),
|
| 30 |
-
# Add more questions...
|
| 31 |
],
|
| 32 |
"Science": [
|
| 33 |
("What is the chemical symbol for water?", ["H2O", "CO2", "O2", "H2"], "H2O"),
|
|
@@ -35,7 +34,6 @@ questions_db = {
|
|
| 35 |
("What planet is known as the Red Planet?", ["Venus", "Mars", "Jupiter", "Saturn"], "Mars"),
|
| 36 |
("Who developed the theory of relativity?", ["Isaac Newton", "Albert Einstein", "Nikola Tesla", "Marie Curie"], "Albert Einstein"),
|
| 37 |
("What is the largest organ in the human body?", ["Heart", "Skin", "Lungs", "Brain"], "Skin"),
|
| 38 |
-
# Add more questions...
|
| 39 |
],
|
| 40 |
"Math": [
|
| 41 |
("What is 5 * 12?", ["50", "60", "55", "70"], "60"),
|
|
@@ -43,7 +41,6 @@ questions_db = {
|
|
| 43 |
("What is 15 + 25?", ["35", "40", "45", "50"], "40"),
|
| 44 |
("What is the value of pi?", ["3.14", "3.15", "3.16", "3.17"], "3.14"),
|
| 45 |
("What is 20 / 4?", ["5", "6", "7", "8"], "5"),
|
| 46 |
-
# Add more questions...
|
| 47 |
],
|
| 48 |
"IPL": [
|
| 49 |
("Which IPL team won the 2020 IPL season?", ["Mumbai Indians", "Delhi Capitals", "Royal Challengers Bangalore", "Chennai Super Kings"], "Mumbai Indians"),
|
|
@@ -51,7 +48,6 @@ questions_db = {
|
|
| 51 |
("Who won the first-ever IPL match?", ["Kolkata Knight Riders", "Royal Challengers Bangalore", "Chennai Super Kings", "Mumbai Indians"], "Kolkata Knight Riders"),
|
| 52 |
("Which IPL team is known as the 'Yellow Army'?", ["Chennai Super Kings", "Mumbai Indians", "Delhi Capitals", "Sunrisers Hyderabad"], "Chennai Super Kings"),
|
| 53 |
("Who hit the most sixes in the 2020 IPL season?", ["Shivam Dube", "AB de Villiers", "Ishan Kishan", "Kieron Pollard"], "Ishan Kishan"),
|
| 54 |
-
# Add more questions...
|
| 55 |
]
|
| 56 |
}
|
| 57 |
|
|
@@ -175,35 +171,18 @@ def start_game(game_data):
|
|
| 175 |
|
| 176 |
st.success(f"Game Over! Your final score is {score}")
|
| 177 |
|
| 178 |
-
# Function to display the leaderboard
|
| 179 |
def display_dashboard():
|
| 180 |
leaderboard_df = load_leaderboard()
|
| 181 |
|
| 182 |
st.subheader("Top 3 Players")
|
| 183 |
top_3 = leaderboard_df.head(3)
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
# Pie chart for the distribution of player scores
|
| 188 |
-
fig = go.Figure(data=[go.Pie(labels=leaderboard_df['name'], values=leaderboard_df['score'], hole=0.3)])
|
| 189 |
-
fig.update_layout(title="Score Distribution")
|
| 190 |
-
st.plotly_chart(fig)
|
| 191 |
-
|
| 192 |
-
# Bar chart of leaderboard rankings
|
| 193 |
-
fig = px.bar(
|
| 194 |
-
leaderboard_df,
|
| 195 |
-
x='name',
|
| 196 |
-
y='score',
|
| 197 |
-
color='name',
|
| 198 |
-
title="Leaderboard",
|
| 199 |
-
labels={'name': 'Player', 'score': 'Score'},
|
| 200 |
-
hover_data=["avatar"]
|
| 201 |
-
)
|
| 202 |
-
st.plotly_chart(fig)
|
| 203 |
-
|
| 204 |
-
# Animation for first-place winner (balloon effect)
|
| 205 |
-
first_place = leaderboard_df.iloc[0] if not leaderboard_df.empty else None
|
| 206 |
if first_place is not None:
|
|
|
|
|
|
|
| 207 |
html_code = f"""
|
| 208 |
<div style="text-align: center;">
|
| 209 |
<h2>π Winner: {first_place['name']} π</h2>
|
|
@@ -223,6 +202,71 @@ def display_dashboard():
|
|
| 223 |
"""
|
| 224 |
html(html_code)
|
| 225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
# Main function to handle Streamlit app
|
| 227 |
def main():
|
| 228 |
st.title('AI Quiz Game')
|
|
@@ -243,6 +287,5 @@ def main():
|
|
| 243 |
elif mode == "Leaderboard":
|
| 244 |
display_dashboard()
|
| 245 |
|
| 246 |
-
# Run the Streamlit app
|
| 247 |
if __name__ == "__main__":
|
| 248 |
main()
|
|
|
|
| 27 |
("Which river flows through Egypt?", ["Nile", "Amazon", "Ganges", "Yangtze"], "Nile"),
|
| 28 |
("What is the capital of Japan?", ["Tokyo", "Kyoto", "Osaka", "Sapporo"], "Tokyo"),
|
| 29 |
("Which is the smallest country in the world?", ["Monaco", "Vatican City", "San Marino", "Liechtenstein"], "Vatican City"),
|
|
|
|
| 30 |
],
|
| 31 |
"Science": [
|
| 32 |
("What is the chemical symbol for water?", ["H2O", "CO2", "O2", "H2"], "H2O"),
|
|
|
|
| 34 |
("What planet is known as the Red Planet?", ["Venus", "Mars", "Jupiter", "Saturn"], "Mars"),
|
| 35 |
("Who developed the theory of relativity?", ["Isaac Newton", "Albert Einstein", "Nikola Tesla", "Marie Curie"], "Albert Einstein"),
|
| 36 |
("What is the largest organ in the human body?", ["Heart", "Skin", "Lungs", "Brain"], "Skin"),
|
|
|
|
| 37 |
],
|
| 38 |
"Math": [
|
| 39 |
("What is 5 * 12?", ["50", "60", "55", "70"], "60"),
|
|
|
|
| 41 |
("What is 15 + 25?", ["35", "40", "45", "50"], "40"),
|
| 42 |
("What is the value of pi?", ["3.14", "3.15", "3.16", "3.17"], "3.14"),
|
| 43 |
("What is 20 / 4?", ["5", "6", "7", "8"], "5"),
|
|
|
|
| 44 |
],
|
| 45 |
"IPL": [
|
| 46 |
("Which IPL team won the 2020 IPL season?", ["Mumbai Indians", "Delhi Capitals", "Royal Challengers Bangalore", "Chennai Super Kings"], "Mumbai Indians"),
|
|
|
|
| 48 |
("Who won the first-ever IPL match?", ["Kolkata Knight Riders", "Royal Challengers Bangalore", "Chennai Super Kings", "Mumbai Indians"], "Kolkata Knight Riders"),
|
| 49 |
("Which IPL team is known as the 'Yellow Army'?", ["Chennai Super Kings", "Mumbai Indians", "Delhi Capitals", "Sunrisers Hyderabad"], "Chennai Super Kings"),
|
| 50 |
("Who hit the most sixes in the 2020 IPL season?", ["Shivam Dube", "AB de Villiers", "Ishan Kishan", "Kieron Pollard"], "Ishan Kishan"),
|
|
|
|
| 51 |
]
|
| 52 |
}
|
| 53 |
|
|
|
|
| 171 |
|
| 172 |
st.success(f"Game Over! Your final score is {score}")
|
| 173 |
|
| 174 |
+
# Function to display the leaderboard with animations
|
| 175 |
def display_dashboard():
|
| 176 |
leaderboard_df = load_leaderboard()
|
| 177 |
|
| 178 |
st.subheader("Top 3 Players")
|
| 179 |
top_3 = leaderboard_df.head(3)
|
| 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>
|
|
|
|
| 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 |
+
# Third Place Winner - Celebration Animation
|
| 230 |
+
if len(top_3) > 2:
|
| 231 |
+
third_place = top_3.iloc[2]
|
| 232 |
+
st.write(f"π₯ {third_place['name']} - {third_place['score']} points! {third_place['avatar']}")
|
| 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>π₯ Third Place: {third_place['name']} π₯</h2>
|
| 237 |
+
<p>Score: {third_place['score']}</p>
|
| 238 |
+
<p>Avatar: {third_place['avatar']}</p>
|
| 239 |
+
</div>
|
| 240 |
+
<div style="animation: thumbsUp 1s linear infinite;">
|
| 241 |
+
π
|
| 242 |
+
</div>
|
| 243 |
+
<style>
|
| 244 |
+
@keyframes thumbsUp {{
|
| 245 |
+
0% {{ transform: rotate(0deg); }}
|
| 246 |
+
50% {{ transform: rotate(20deg); }}
|
| 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')
|
|
|
|
| 287 |
elif mode == "Leaderboard":
|
| 288 |
display_dashboard()
|
| 289 |
|
|
|
|
| 290 |
if __name__ == "__main__":
|
| 291 |
main()
|