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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from typing import Dict, List, Tuple
|
| 3 |
+
|
| 4 |
+
class JeopardyGame:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.questions = {
|
| 7 |
+
"NGSS Standards": {
|
| 8 |
+
200: {
|
| 9 |
+
"question": "These are the three dimensions of learning in NGSS that work together to help children make sense of the world around us.",
|
| 10 |
+
"answer": "What are Disciplinary Core Ideas (DCIs), Science and Engineering Practices (SEPs), and Crosscutting Concepts (CCCs)?"
|
| 11 |
+
},
|
| 12 |
+
400: {
|
| 13 |
+
"question": "In the NGSS documents, this color represents Science and Engineering Practices, while orange represents Disciplinary Core Ideas.",
|
| 14 |
+
"answer": "What is blue?"
|
| 15 |
+
},
|
| 16 |
+
600: {
|
| 17 |
+
"question": "These standards are measurable and observable, providing the learning goals for what children should understand and be able to do.",
|
| 18 |
+
"answer": "What are performance expectations?"
|
| 19 |
+
},
|
| 20 |
+
800: {
|
| 21 |
+
"question": "These ideas, represented in green, are not specific to any one discipline but cut across all of them.",
|
| 22 |
+
"answer": "What are crosscutting concepts?"
|
| 23 |
+
},
|
| 24 |
+
1000: {
|
| 25 |
+
"question": "The performance expectations are written using this format: Grade-DCI-Number, such as 2-LS2-1, where LS refers to this specific Disciplinary Core Idea.",
|
| 26 |
+
"answer": "What is Life Sciences?"
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
"EDI425/525 Trivia": {
|
| 30 |
+
200: {
|
| 31 |
+
"question": "This member of our class, who created the jeopardy game, keeps giving you assignments.",
|
| 32 |
+
"answer": "Who is Sule/Dr. Aksoy?"
|
| 33 |
+
},
|
| 34 |
+
400: {
|
| 35 |
+
"question": "This first assignment required you to reflect on your personal experiences with science in and out of school.",
|
| 36 |
+
"answer": "What is a science autobiography?"
|
| 37 |
+
},
|
| 38 |
+
600: {
|
| 39 |
+
"question": "This major assignment involved creating a detailed plan for engaging your children in scientific discourse.",
|
| 40 |
+
"answer": "What is Science Talk Plan?"
|
| 41 |
+
},
|
| 42 |
+
800: {
|
| 43 |
+
"question": "This activity engaged you in sensemaking while exploring light phenomena in the dark room.",
|
| 44 |
+
"answer": "What is the colored shadows demo?"
|
| 45 |
+
},
|
| 46 |
+
1000: {
|
| 47 |
+
"question": "This short practice helps us develop a road map for a project-based science learning unit.",
|
| 48 |
+
"answer": "What is creating a driving question board?"
|
| 49 |
+
}
|
| 50 |
+
},
|
| 51 |
+
"SUNY Brockport": {
|
| 52 |
+
200: {
|
| 53 |
+
"question": "This online learning management system is used for submitting assignments and accessing course materials.",
|
| 54 |
+
"answer": "What is Brightspace?"
|
| 55 |
+
},
|
| 56 |
+
400: {
|
| 57 |
+
"question": "This is the official mascot of SUNY Brockport's athletic teams.",
|
| 58 |
+
"answer": "Who is Ellsworth the Golden Eagle?"
|
| 59 |
+
},
|
| 60 |
+
600: {
|
| 61 |
+
"question": "Brockport's campus sits on mile 288 of this historic waterway.",
|
| 62 |
+
"answer": "What is the Erie Canal?"
|
| 63 |
+
},
|
| 64 |
+
800: {
|
| 65 |
+
"question": "This place in Drake Memorial Library serves not artisanal but hot and necessary brew.",
|
| 66 |
+
"answer": "What is Pages Cafe?"
|
| 67 |
+
},
|
| 68 |
+
1000: {
|
| 69 |
+
"question": "This is the oldest building on the main campus, built in 1941.",
|
| 70 |
+
"answer": "What is Hartwell Hall?"
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
self.used_questions = set()
|
| 76 |
+
self.scores = {"Group 1": 0, "Group 2": 0, "Group 3": 0, "Group 4": 0}
|
| 77 |
+
self.current_question = None
|
| 78 |
+
self.current_value = 0
|
| 79 |
+
self.question_answered = False
|
| 80 |
+
|
| 81 |
+
def get_board_state(self) -> str:
|
| 82 |
+
"""Create the current board state as an HTML table"""
|
| 83 |
+
html = '<table style="width:100%; text-align:center; border-collapse: collapse;">'
|
| 84 |
+
html += '<tr style="background-color: #1e3a8a; color: white; font-weight: bold;">'
|
| 85 |
+
|
| 86 |
+
# Header row with categories
|
| 87 |
+
for category in self.questions.keys():
|
| 88 |
+
html += f'<th style="padding: 15px; border: 2px solid white;">{category}</th>'
|
| 89 |
+
html += '</tr>'
|
| 90 |
+
|
| 91 |
+
# Value rows
|
| 92 |
+
for value in [200, 400, 600, 800, 1000]:
|
| 93 |
+
html += '<tr>'
|
| 94 |
+
for category in self.questions.keys():
|
| 95 |
+
key = f"{category}-{value}"
|
| 96 |
+
if key in self.used_questions:
|
| 97 |
+
html += '<td style="padding: 20px; border: 2px solid #ccc; background-color: #e0e0e0; color: #999;">USED</td>'
|
| 98 |
+
else:
|
| 99 |
+
html += f'<td style="padding: 20px; border: 2px solid #ccc; background-color: #3b82f6; color: white; font-weight: bold; font-size: 1.2em;">${value}</td>'
|
| 100 |
+
html += '</tr>'
|
| 101 |
+
|
| 102 |
+
html += '</table>'
|
| 103 |
+
return html
|
| 104 |
+
|
| 105 |
+
def select_question(self, category: str, value: int) -> Tuple[str, str, str]:
|
| 106 |
+
"""Select a question and mark it as used"""
|
| 107 |
+
if not category or not value:
|
| 108 |
+
return "Please select both a category and value.", self.get_board_state(), self.get_scores()
|
| 109 |
+
|
| 110 |
+
key = f"{category}-{value}"
|
| 111 |
+
|
| 112 |
+
if key in self.used_questions:
|
| 113 |
+
return "This question has already been selected! Choose another.", self.get_board_state(), self.get_scores()
|
| 114 |
+
|
| 115 |
+
self.used_questions.add(key)
|
| 116 |
+
self.current_question = self.questions[category][value]
|
| 117 |
+
self.current_value = value
|
| 118 |
+
self.question_answered = False
|
| 119 |
+
|
| 120 |
+
question_text = f"### {category} for ${value}\n\n**{self.current_question['question']}**"
|
| 121 |
+
|
| 122 |
+
return question_text, self.get_board_state(), self.get_scores()
|
| 123 |
+
|
| 124 |
+
def check_answer(self, group: str, answer: str) -> Tuple[str, str, str]:
|
| 125 |
+
"""Check if the answer is correct and update scores"""
|
| 126 |
+
if not self.current_question:
|
| 127 |
+
return "Please select a question first!", self.get_board_state(), self.get_scores()
|
| 128 |
+
|
| 129 |
+
if self.question_answered:
|
| 130 |
+
return "This question has already been answered!", self.get_board_state(), self.get_scores()
|
| 131 |
+
|
| 132 |
+
if not answer or answer.strip() == "":
|
| 133 |
+
return "Please enter an answer!", self.get_board_state(), self.get_scores()
|
| 134 |
+
|
| 135 |
+
correct_answer = self.current_question['answer'].lower()
|
| 136 |
+
submitted_answer = answer.lower().strip()
|
| 137 |
+
|
| 138 |
+
# Extract key terms from the correct answer
|
| 139 |
+
key_terms = correct_answer.replace("what is", "").replace("what are", "").replace("who is", "").replace("?", "")
|
| 140 |
+
key_terms = key_terms.replace(",", "").replace(".", "").strip()
|
| 141 |
+
|
| 142 |
+
# Special handling for different types of answers
|
| 143 |
+
is_correct = False
|
| 144 |
+
|
| 145 |
+
# Check for NGSS terms
|
| 146 |
+
if "dci" in key_terms or "sep" in key_terms:
|
| 147 |
+
matches = 0
|
| 148 |
+
if "dci" in submitted_answer or "disciplinary core" in submitted_answer:
|
| 149 |
+
matches += 1
|
| 150 |
+
if "sep" in submitted_answer or "science and engineering" in submitted_answer:
|
| 151 |
+
matches += 1
|
| 152 |
+
if "ccc" in submitted_answer or "crosscutting" in submitted_answer:
|
| 153 |
+
matches += 1
|
| 154 |
+
is_correct = matches >= 2
|
| 155 |
+
# Check for name questions
|
| 156 |
+
elif "sule" in key_terms or "aksoy" in key_terms:
|
| 157 |
+
is_correct = "sule" in submitted_answer or "aksoy" in submitted_answer or "dr" in submitted_answer
|
| 158 |
+
# Check for answers with alternatives
|
| 159 |
+
elif "ellsworth" in key_terms or "golden eagle" in key_terms:
|
| 160 |
+
is_correct = "ellsworth" in submitted_answer or "golden eagle" in submitted_answer or "eagle" in submitted_answer
|
| 161 |
+
# Default checking
|
| 162 |
+
else:
|
| 163 |
+
important_words = [word for word in key_terms.split() if len(word) > 3]
|
| 164 |
+
if important_words:
|
| 165 |
+
matches = sum(1 for word in important_words if word in submitted_answer)
|
| 166 |
+
is_correct = matches >= max(1, len(important_words) * 0.5)
|
| 167 |
+
else:
|
| 168 |
+
is_correct = key_terms in submitted_answer
|
| 169 |
+
|
| 170 |
+
if is_correct:
|
| 171 |
+
self.scores[group] += self.current_value
|
| 172 |
+
result = f"β
**CORRECT!** {group} earns ${self.current_value}!\n\nCorrect answer: {self.current_question['answer']}"
|
| 173 |
+
else:
|
| 174 |
+
self.scores[group] -= self.current_value
|
| 175 |
+
result = f"β **INCORRECT!** {group} loses ${self.current_value}.\n\nCorrect answer: {self.current_question['answer']}"
|
| 176 |
+
|
| 177 |
+
self.question_answered = True
|
| 178 |
+
return result, self.get_board_state(), self.get_scores()
|
| 179 |
+
|
| 180 |
+
def get_scores(self) -> str:
|
| 181 |
+
"""Return current scores and microteaching order"""
|
| 182 |
+
sorted_scores = sorted(self.scores.items(), key=lambda x: x[1], reverse=True)
|
| 183 |
+
|
| 184 |
+
scores_text = "## π Current Standings\n\n"
|
| 185 |
+
scores_text += "### Microteaching Schedule:\n"
|
| 186 |
+
|
| 187 |
+
for i, (group, score) in enumerate(sorted_scores):
|
| 188 |
+
if i < 2:
|
| 189 |
+
scores_text += f"**Week 1:** {group} (${score})\n"
|
| 190 |
+
else:
|
| 191 |
+
scores_text += f"**Week 2:** {group} (${score})\n"
|
| 192 |
+
|
| 193 |
+
scores_text += "\n### Scores:\n"
|
| 194 |
+
for i, (group, score) in enumerate(sorted_scores, 1):
|
| 195 |
+
emoji = "π₯" if i == 1 else "π₯" if i == 2 else "π₯" if i == 3 else "π"
|
| 196 |
+
scores_text += f"{emoji} {group}: ${score}\n"
|
| 197 |
+
|
| 198 |
+
return scores_text
|
| 199 |
+
|
| 200 |
+
def reset_game(self):
|
| 201 |
+
"""Reset the entire game"""
|
| 202 |
+
self.used_questions.clear()
|
| 203 |
+
self.scores = {"Group 1": 0, "Group 2": 0, "Group 3": 0, "Group 4": 0}
|
| 204 |
+
self.current_question = None
|
| 205 |
+
self.current_value = 0
|
| 206 |
+
self.question_answered = False
|
| 207 |
+
return "Game has been reset!", self.get_board_state(), self.get_scores()
|
| 208 |
+
|
| 209 |
+
# Initialize game
|
| 210 |
+
game = JeopardyGame()
|
| 211 |
+
|
| 212 |
+
# Create interface
|
| 213 |
+
with gr.Blocks(title="EDI425/525 Jeopardy") as demo:
|
| 214 |
+
gr.Markdown("# π EDI425/525 Classroom Jeopardy\n### Determine your microteaching order through friendly competition!")
|
| 215 |
+
|
| 216 |
+
with gr.Row():
|
| 217 |
+
with gr.Column(scale=3):
|
| 218 |
+
gr.Markdown("## Game Board")
|
| 219 |
+
board_display = gr.HTML(value=game.get_board_state())
|
| 220 |
+
|
| 221 |
+
gr.Markdown("### Select a Question:")
|
| 222 |
+
with gr.Row():
|
| 223 |
+
category_select = gr.Dropdown(
|
| 224 |
+
choices=list(game.questions.keys()),
|
| 225 |
+
label="Category",
|
| 226 |
+
value="NGSS Standards"
|
| 227 |
+
)
|
| 228 |
+
value_select = gr.Dropdown(
|
| 229 |
+
choices=[200, 400, 600, 800, 1000],
|
| 230 |
+
label="Value",
|
| 231 |
+
value=200
|
| 232 |
+
)
|
| 233 |
+
select_btn = gr.Button("Select Question", variant="primary")
|
| 234 |
+
|
| 235 |
+
question_display = gr.Markdown(value="### Ready to play!\n\nSelect a category and value above.")
|
| 236 |
+
|
| 237 |
+
with gr.Column(scale=2):
|
| 238 |
+
scores_display = gr.Markdown(value=game.get_scores())
|
| 239 |
+
|
| 240 |
+
gr.Markdown("## Submit Answer")
|
| 241 |
+
group_select = gr.Dropdown(
|
| 242 |
+
choices=["Group 1", "Group 2", "Group 3", "Group 4"],
|
| 243 |
+
label="Your Group",
|
| 244 |
+
value="Group 1"
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
answer_input = gr.Textbox(
|
| 248 |
+
label="Your Answer",
|
| 249 |
+
placeholder="Remember: 'What is...?' or 'Who is...?'",
|
| 250 |
+
lines=2
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
submit_btn = gr.Button("Submit Answer", variant="primary")
|
| 254 |
+
result_display = gr.Markdown(value="")
|
| 255 |
+
|
| 256 |
+
reset_btn = gr.Button("Reset Game", variant="stop")
|
| 257 |
+
|
| 258 |
+
# Event handlers
|
| 259 |
+
select_btn.click(
|
| 260 |
+
fn=lambda cat, val: game.select_question(cat, val),
|
| 261 |
+
inputs=[category_select, value_select],
|
| 262 |
+
outputs=[question_display, board_display, scores_display]
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
submit_btn.click(
|
| 266 |
+
fn=lambda g, a: game.check_answer(g, a),
|
| 267 |
+
inputs=[group_select, answer_input],
|
| 268 |
+
outputs=[result_display, board_display, scores_display]
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
reset_btn.click(
|
| 272 |
+
fn=lambda: game.reset_game(),
|
| 273 |
+
outputs=[result_display, board_display, scores_display]
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
# Launch
|
| 277 |
+
if __name__ == "__main__":
|
| 278 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio
|