Jonathan Bejarano commited on
Commit
75dae40
·
1 Parent(s): 8e673c2

US375432 - update game modes and examples for improved gameplay experience

Browse files
Files changed (3) hide show
  1. .gitignore +2 -1
  2. app.py +70 -8
  3. game.py +3 -0
.gitignore CHANGED
@@ -3,4 +3,5 @@
3
  __pycache__/
4
  *.py[cod]
5
  *$py.class
6
- .pytest_cache/
 
 
3
  __pycache__/
4
  *.py[cod]
5
  *$py.class
6
+ .pytest_cache/
7
+ geography_data/
app.py CHANGED
@@ -119,8 +119,21 @@ if ai.LOCAL_MODE:
119
  else:
120
  description = "Choose your game mode and I'll think of a location for you to guess with 20 yes or no questions!"
121
 
122
- # Common examples and settings - updated to be more generic
123
- examples = [
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  ["Is it located in North America?"],
125
  ["Is it in the Northern Hemisphere?"],
126
  ["Does it border an ocean?"],
@@ -130,18 +143,28 @@ examples = [
130
  ["Was it ever a British colony?"],
131
  ["Is it located on an island?"],
132
  ["Does it use the US Dollar as currency?"],
133
- ["Is it a landlocked location?"],
134
  ]
135
 
 
 
 
136
  # Create wrapper function that handles both local and cloud modes
137
  # Local mode wrapper function
138
- def custom_respond(message, history, game_mode_selection):
139
  return respond(message, history, "", 4000, 0.3, 0.6, game_mode_selection, None)
140
 
 
 
 
 
 
 
 
141
  with gr.Blocks() as demo:
142
 
143
 
144
- gr.Markdown("# 20 Questions Geography Game")
145
  gr.Markdown(description)
146
 
147
  # Game mode selection at the top
@@ -151,14 +174,53 @@ with gr.Blocks() as demo:
151
  label="Game Mode",
152
  info="Choose what type of location to guess"
153
  )
 
 
 
 
 
 
 
154
 
155
-
156
  chatbot = gr.ChatInterface(
157
  custom_respond,
158
  type="messages",
159
- examples=examples,
160
  cache_examples=False,
161
- additional_inputs=[game.mode_dropdown],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  )
163
  gr.Markdown(
164
  """
 
119
  else:
120
  description = "Choose your game mode and I'll think of a location for you to guess with 20 yes or no questions!"
121
 
122
+ # Mode-specific examples
123
+ examples_states = [
124
+ ["Is it on the East Coast?"],
125
+ ["Is it in the Western United States?"],
126
+ ["Does it border an ocean?"],
127
+ ["Does it border Canada?"],
128
+ ["Is it larger than Texas?"],
129
+ ["Was it one of the original 13 colonies?"],
130
+ ["Does it have a major city with over 1 million people?"],
131
+ ["Is it known for agriculture?"],
132
+ ["Does it have mountains?"],
133
+ ["Is it in the Mountain Time Zone?"],
134
+ ]
135
+
136
+ examples_countries = [
137
  ["Is it located in North America?"],
138
  ["Is it in the Northern Hemisphere?"],
139
  ["Does it border an ocean?"],
 
143
  ["Was it ever a British colony?"],
144
  ["Is it located on an island?"],
145
  ["Does it use the US Dollar as currency?"],
146
+ ["Is it a landlocked country?"],
147
  ]
148
 
149
+ # Default examples (will be updated based on mode)
150
+ examples = examples_states
151
+
152
  # Create wrapper function that handles both local and cloud modes
153
  # Local mode wrapper function
154
+ def custom_respond(message, history, game_mode_selection, game_type_selection):
155
  return respond(message, history, "", 4000, 0.3, 0.6, game_mode_selection, None)
156
 
157
+ def get_examples_for_mode(mode):
158
+ """Return examples based on the selected game mode"""
159
+ if mode == game.MODE_STATES:
160
+ return examples_states
161
+ else:
162
+ return examples_countries
163
+
164
  with gr.Blocks() as demo:
165
 
166
 
167
+ gr.Markdown("# Geography AI Tutor")
168
  gr.Markdown(description)
169
 
170
  # Game mode selection at the top
 
174
  label="Game Mode",
175
  info="Choose what type of location to guess"
176
  )
177
+
178
+ game.type_dropdown = gr.Dropdown(
179
+ choices=[game.TYPE_GEOGRAPHY_BEE, game.TYPE_TWENTY_QUESTIONS],
180
+ value=game.TYPE_GEOGRAPHY_BEE,
181
+ label="Game Type",
182
+ info="Choose what type of game to play"
183
+ )
184
 
185
+ # ChatInterface without built-in examples
186
  chatbot = gr.ChatInterface(
187
  custom_respond,
188
  type="messages",
 
189
  cache_examples=False,
190
+ additional_inputs=[game.mode_dropdown, game.type_dropdown],
191
+ )
192
+
193
+ # Add examples separately using Dataset which can be updated
194
+ with gr.Row():
195
+ gr.Markdown("### Example Questions (click to use)")
196
+
197
+ examples_dataset = gr.Dataset(
198
+ components=[chatbot.textbox],
199
+ samples=examples_states,
200
+ type="index"
201
+ )
202
+
203
+ # Update examples when mode changes
204
+ def update_examples(mode):
205
+ return gr.Dataset(samples=get_examples_for_mode(mode))
206
+
207
+ # When an example is clicked, populate the textbox
208
+ def load_example(index, mode):
209
+ examples = get_examples_for_mode(mode)
210
+ if 0 <= index < len(examples):
211
+ return examples[index][0]
212
+ return ""
213
+
214
+ game.mode_dropdown.change(
215
+ fn=update_examples,
216
+ inputs=[game.mode_dropdown],
217
+ outputs=[examples_dataset]
218
+ )
219
+
220
+ examples_dataset.select(
221
+ fn=load_example,
222
+ inputs=[examples_dataset, game.mode_dropdown],
223
+ outputs=[chatbot.textbox]
224
  )
225
  gr.Markdown(
226
  """
game.py CHANGED
@@ -16,6 +16,9 @@ with open(STATES_JSON_PATH, "r", encoding="utf-8") as f:
16
  MODE_COUNTRIES = "Countries of the World"
17
  MODE_STATES = "US States"
18
 
 
 
 
19
 
20
  current_system = ""
21
  selected_country = ""
 
16
  MODE_COUNTRIES = "Countries of the World"
17
  MODE_STATES = "US States"
18
 
19
+ TYPE_TWENTY_QUESTIONS = "20 Questions Geography Game"
20
+ TYPE_GEOGRAPHY_BEE = "Geography Bee"
21
+
22
 
23
  current_system = ""
24
  selected_country = ""