Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
|
3 |
import random
|
4 |
import gradio as gr
|
@@ -118,6 +118,38 @@ def get_ai_response(suspect_name, player_input):
|
|
118 |
response = llm_inference(messages)
|
119 |
return response.strip()
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
def process_input(player_input):
|
122 |
if game_state["is_game_over"]:
|
123 |
return "The game is over. Please restart to play again.", game_state["history"]
|
@@ -130,13 +162,20 @@ def process_input(player_input):
|
|
130 |
game_state["history"].append(("System", result))
|
131 |
return result, game_state["history"]
|
132 |
else:
|
133 |
-
for suspect_name in suspect_names
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
def extract_clues(ai_response):
|
142 |
clues = []
|
@@ -215,6 +254,7 @@ with gr.Blocks() as demo:
|
|
215 |
with gr.Column():
|
216 |
gr.Markdown("## Commands")
|
217 |
gr.Markdown("- **Ask a question to a suspect**: Include the suspect's name in your question.\n Example: *\"Miss Scarlett, where were you during the evening?\"*")
|
|
|
218 |
gr.Markdown("- **Make an accusation**: Include the word *\"accuse\"*.\n Example: *\"I accuse Colonel Mustard with the Rope in the Study.\"*")
|
219 |
player_input = gr.Textbox(lines=1, label="Your Input")
|
220 |
send_button = gr.Button("Send")
|
|
|
1 |
+
|
2 |
|
3 |
import random
|
4 |
import gradio as gr
|
|
|
118 |
response = llm_inference(messages)
|
119 |
return response.strip()
|
120 |
|
121 |
+
def get_group_response(suspect_names_list, player_input):
|
122 |
+
responses = []
|
123 |
+
for suspect_name in suspect_names_list:
|
124 |
+
suspect = suspects[suspect_name]
|
125 |
+
suspect["anger_level"] += 1
|
126 |
+
personality = suspect["personality"]
|
127 |
+
knowledge = suspect["knowledge"]
|
128 |
+
anger_level = suspect["anger_level"]
|
129 |
+
hot_headed = suspect["hot_headed"]
|
130 |
+
relationships = get_relationships(suspect_name, suspect_names_list)
|
131 |
+
system_prompt = f"You are {suspect_name}, who is {personality}. {knowledge} {relationships}"
|
132 |
+
if hot_headed:
|
133 |
+
system_prompt += f" You are getting angrier each time you are questioned. Your anger level is {anger_level}."
|
134 |
+
if suspect["is_murderer"]:
|
135 |
+
system_prompt += " You are the murderer and will lie to protect yourself."
|
136 |
+
user_message = f"The detective asks: \"{player_input}\" As {suspect_name}, respond in first person, staying in character, and interact with the other suspects present."
|
137 |
+
messages = [
|
138 |
+
{"role": "system", "content": system_prompt},
|
139 |
+
{"role": "user", "content": user_message}
|
140 |
+
]
|
141 |
+
response = llm_inference(messages)
|
142 |
+
responses.append(f"**{suspect_name}:** {response.strip()}")
|
143 |
+
return "\n\n".join(responses)
|
144 |
+
|
145 |
+
def get_relationships(suspect_name, suspect_names_list):
|
146 |
+
other_suspects = [name for name in suspect_names_list if name != suspect_name]
|
147 |
+
if other_suspects:
|
148 |
+
relationships = f"You are currently with {', '.join(other_suspects)}. You might have personal opinions about them, and you may attempt to shift blame onto them."
|
149 |
+
else:
|
150 |
+
relationships = ""
|
151 |
+
return relationships
|
152 |
+
|
153 |
def process_input(player_input):
|
154 |
if game_state["is_game_over"]:
|
155 |
return "The game is over. Please restart to play again.", game_state["history"]
|
|
|
162 |
game_state["history"].append(("System", result))
|
163 |
return result, game_state["history"]
|
164 |
else:
|
165 |
+
mentioned_suspects = [suspect_name for suspect_name in suspect_names if suspect_name.lower() in player_input.lower()]
|
166 |
+
if len(mentioned_suspects) == 0:
|
167 |
+
return "Please direct your question to a suspect.", game_state["history"]
|
168 |
+
elif len(mentioned_suspects) == 1:
|
169 |
+
suspect_name = mentioned_suspects[0]
|
170 |
+
ai_response = get_ai_response(suspect_name, player_input)
|
171 |
+
game_state["history"].append((suspect_name, ai_response))
|
172 |
+
extract_clues(ai_response)
|
173 |
+
return ai_response, game_state["history"]
|
174 |
+
else:
|
175 |
+
ai_response = get_group_response(mentioned_suspects, player_input)
|
176 |
+
game_state["history"].append(("Group", ai_response))
|
177 |
+
extract_clues(ai_response)
|
178 |
+
return ai_response, game_state["history"]
|
179 |
|
180 |
def extract_clues(ai_response):
|
181 |
clues = []
|
|
|
254 |
with gr.Column():
|
255 |
gr.Markdown("## Commands")
|
256 |
gr.Markdown("- **Ask a question to a suspect**: Include the suspect's name in your question.\n Example: *\"Miss Scarlett, where were you during the evening?\"*")
|
257 |
+
gr.Markdown("- **Interrogate multiple suspects**: Include multiple suspects' names in your question.\n Example: *\"Colonel Mustard and Mrs. Peacock, what can you tell me about the night?\"*")
|
258 |
gr.Markdown("- **Make an accusation**: Include the word *\"accuse\"*.\n Example: *\"I accuse Colonel Mustard with the Rope in the Study.\"*")
|
259 |
player_input = gr.Textbox(lines=1, label="Your Input")
|
260 |
send_button = gr.Button("Send")
|