Update app.py
Browse files
app.py
CHANGED
|
@@ -197,7 +197,7 @@ def get_group_response(suspect_names_list, player_input):
|
|
| 197 |
responses.append(f"**{suspect_name}:** {response.strip()}")
|
| 198 |
return "\n\n".join(responses)
|
| 199 |
|
| 200 |
-
def process_input(player_input):
|
| 201 |
if game_state["is_game_over"]:
|
| 202 |
return "The game is over. Please restart to play again.", game_state["history"]
|
| 203 |
if game_state["accused"]:
|
|
@@ -230,35 +230,22 @@ def process_input(player_input):
|
|
| 230 |
game_state["history"].append(("System", result))
|
| 231 |
return result, game_state["history"]
|
| 232 |
else:
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
suspect_name = mentioned_suspects[0]
|
| 238 |
ai_response = get_ai_response(suspect_name, player_input)
|
| 239 |
game_state["history"].append((suspect_name, ai_response))
|
| 240 |
extract_clues(ai_response)
|
| 241 |
return ai_response, game_state["history"]
|
| 242 |
else:
|
| 243 |
-
ai_response = get_group_response(
|
| 244 |
game_state["history"].append(("Group", ai_response))
|
| 245 |
extract_clues(ai_response)
|
| 246 |
return ai_response, game_state["history"]
|
| 247 |
|
| 248 |
def extract_clues(ai_response):
|
| 249 |
-
|
| 250 |
-
for weapon in weapons:
|
| 251 |
-
if weapon.lower() in ai_response.lower() and weapon != game_state["weapon"]:
|
| 252 |
-
clues.append(f"The weapon is not the {weapon}.")
|
| 253 |
-
for location in locations:
|
| 254 |
-
if location.lower() in ai_response.lower() and location != game_state["location"]:
|
| 255 |
-
clues.append(f"The location is not the {location}.")
|
| 256 |
-
for suspect_name in suspect_names:
|
| 257 |
-
if suspect_name.lower() in ai_response.lower() and suspect_name != game_state["murderer"]:
|
| 258 |
-
clues.append(f"{suspect_name} is not the murderer.")
|
| 259 |
-
for clue in clues:
|
| 260 |
-
if clue not in game_state["clues"]:
|
| 261 |
-
game_state["clues"].append(clue)
|
| 262 |
|
| 263 |
def search_location(location):
|
| 264 |
if location not in locations:
|
|
@@ -348,13 +335,12 @@ def endgame_reveal(player_input):
|
|
| 348 |
game_state["is_game_over"] = True
|
| 349 |
return "Your deductions have inaccuracies. The murderer denies your claims and escapes justice."
|
| 350 |
|
| 351 |
-
def chat_interface(player_input):
|
| 352 |
-
response, history = process_input(player_input)
|
| 353 |
chat_history = ""
|
| 354 |
for speaker, text in history:
|
| 355 |
chat_history += f"**{speaker}:** {text}\n\n"
|
| 356 |
-
|
| 357 |
-
return chat_history, clues_display
|
| 358 |
|
| 359 |
def get_debug_info():
|
| 360 |
debug_info = ""
|
|
@@ -380,47 +366,35 @@ def get_debug_info():
|
|
| 380 |
|
| 381 |
def restart_game():
|
| 382 |
initialize_game()
|
| 383 |
-
return "", "",
|
| 384 |
|
| 385 |
with gr.Blocks() as demo:
|
| 386 |
-
gr.Markdown("#
|
| 387 |
with gr.Tabs():
|
| 388 |
with gr.TabItem("Game"):
|
| 389 |
with gr.Row():
|
| 390 |
with gr.Column():
|
| 391 |
-
gr.Markdown("##
|
| 392 |
-
gr.Markdown("- **Ask a question
|
| 393 |
-
gr.Markdown("- **
|
| 394 |
-
gr.Markdown("- **
|
| 395 |
-
gr.
|
| 396 |
-
gr.Markdown("- **Bluff a suspect**: Type *\"Bluff [Suspect]\"*")
|
| 397 |
-
gr.Markdown("- **Analyze a response**: Type *\"Analyze\"*")
|
| 398 |
-
gr.Markdown("- **Reveal your deductions**: Type *\"Reveal: [Your deductions]\"*")
|
| 399 |
-
gr.Markdown("- **Make an accusation**: Include the word *\"accuse\"*.")
|
| 400 |
player_input = gr.Textbox(lines=1, label="Your Input")
|
| 401 |
send_button = gr.Button("Send")
|
| 402 |
restart_button = gr.Button("Restart Game")
|
| 403 |
-
chatbox = gr.Textbox(lines=
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
gr.Markdown(', '.join(weapons))
|
| 409 |
-
gr.Markdown("## Locations")
|
| 410 |
-
gr.Markdown(', '.join(locations))
|
| 411 |
-
clues = gr.Textbox(lines=15, label="Discovered Clues", interactive=False)
|
| 412 |
-
with gr.TabItem("Debug"):
|
| 413 |
-
debug_info = gr.Textbox(lines=30, label="Debug Information", interactive=False)
|
| 414 |
-
update_debug_button = gr.Button("Update Debug Info")
|
| 415 |
-
update_debug_button.click(fn=lambda: get_debug_info(), inputs=None, outputs=debug_info)
|
| 416 |
|
| 417 |
-
def send_message(player_input):
|
| 418 |
-
chat_history
|
| 419 |
debug_information = get_debug_info()
|
| 420 |
-
return chat_history, "",
|
| 421 |
|
| 422 |
-
send_button.click(send_message, inputs=player_input, outputs=[chatbox, player_input,
|
| 423 |
-
restart_button.click(fn=restart_game, inputs=None, outputs=[chatbox,
|
| 424 |
|
| 425 |
initialize_game()
|
| 426 |
demo.launch()
|
|
|
|
| 197 |
responses.append(f"**{suspect_name}:** {response.strip()}")
|
| 198 |
return "\n\n".join(responses)
|
| 199 |
|
| 200 |
+
def process_input(player_input, selected_suspects):
|
| 201 |
if game_state["is_game_over"]:
|
| 202 |
return "The game is over. Please restart to play again.", game_state["history"]
|
| 203 |
if game_state["accused"]:
|
|
|
|
| 230 |
game_state["history"].append(("System", result))
|
| 231 |
return result, game_state["history"]
|
| 232 |
else:
|
| 233 |
+
if not selected_suspects:
|
| 234 |
+
return "Please select at least one suspect to question.", game_state["history"]
|
| 235 |
+
elif len(selected_suspects) == 1:
|
| 236 |
+
suspect_name = selected_suspects[0]
|
|
|
|
| 237 |
ai_response = get_ai_response(suspect_name, player_input)
|
| 238 |
game_state["history"].append((suspect_name, ai_response))
|
| 239 |
extract_clues(ai_response)
|
| 240 |
return ai_response, game_state["history"]
|
| 241 |
else:
|
| 242 |
+
ai_response = get_group_response(selected_suspects, player_input)
|
| 243 |
game_state["history"].append(("Group", ai_response))
|
| 244 |
extract_clues(ai_response)
|
| 245 |
return ai_response, game_state["history"]
|
| 246 |
|
| 247 |
def extract_clues(ai_response):
|
| 248 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
def search_location(location):
|
| 251 |
if location not in locations:
|
|
|
|
| 335 |
game_state["is_game_over"] = True
|
| 336 |
return "Your deductions have inaccuracies. The murderer denies your claims and escapes justice."
|
| 337 |
|
| 338 |
+
def chat_interface(player_input, selected_suspects):
|
| 339 |
+
response, history = process_input(player_input, selected_suspects)
|
| 340 |
chat_history = ""
|
| 341 |
for speaker, text in history:
|
| 342 |
chat_history += f"**{speaker}:** {text}\n\n"
|
| 343 |
+
return chat_history
|
|
|
|
| 344 |
|
| 345 |
def get_debug_info():
|
| 346 |
debug_info = ""
|
|
|
|
| 366 |
|
| 367 |
def restart_game():
|
| 368 |
initialize_game()
|
| 369 |
+
return "", "", []
|
| 370 |
|
| 371 |
with gr.Blocks() as demo:
|
| 372 |
+
gr.Markdown("# Cluedo")
|
| 373 |
with gr.Tabs():
|
| 374 |
with gr.TabItem("Game"):
|
| 375 |
with gr.Row():
|
| 376 |
with gr.Column():
|
| 377 |
+
gr.Markdown("## Instructions")
|
| 378 |
+
gr.Markdown("- **Ask a question**: Type your question.")
|
| 379 |
+
gr.Markdown("- **Select Suspects**: Click on the suspects you want to question.")
|
| 380 |
+
gr.Markdown("- **Other Actions**: Type commands like *\"Search [Location]\"*, *\"Eavesdrop\"*, *\"Bluff [Suspect]\"*, *\"Analyze\"*, *\"Reveal: [Your deductions]\"*, or include *\"accuse\"* to make an accusation.")
|
| 381 |
+
suspect_selection = gr.CheckboxGroup(choices=suspect_names, label="Select Suspects to Question")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
player_input = gr.Textbox(lines=1, label="Your Input")
|
| 383 |
send_button = gr.Button("Send")
|
| 384 |
restart_button = gr.Button("Restart Game")
|
| 385 |
+
chatbox = gr.Textbox(lines=20, label="Chat History", interactive=False)
|
| 386 |
+
with gr.TabItem("Debug"):
|
| 387 |
+
debug_info = gr.Textbox(lines=30, label="Debug Information", interactive=False)
|
| 388 |
+
update_debug_button = gr.Button("Update Debug Info")
|
| 389 |
+
update_debug_button.click(fn=lambda: get_debug_info(), inputs=None, outputs=debug_info)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
|
| 391 |
+
def send_message(player_input, selected_suspects):
|
| 392 |
+
chat_history = chat_interface(player_input, selected_suspects)
|
| 393 |
debug_information = get_debug_info()
|
| 394 |
+
return chat_history, "", [], debug_information
|
| 395 |
|
| 396 |
+
send_button.click(send_message, inputs=[player_input, suspect_selection], outputs=[chatbox, player_input, suspect_selection, debug_info])
|
| 397 |
+
restart_button.click(fn=restart_game, inputs=None, outputs=[chatbox, player_input, suspect_selection, debug_info])
|
| 398 |
|
| 399 |
initialize_game()
|
| 400 |
demo.launch()
|