Spaces:
Sleeping
Sleeping
Jonas Wiesli
commited on
Commit
•
99d7111
1
Parent(s):
bb63de8
formatting adjustments
Browse files
app.py
CHANGED
@@ -88,37 +88,37 @@ with gr.Blocks(theme=theme, css=css) as iface:
|
|
88 |
return "", history + [[user_message, None]]
|
89 |
|
90 |
# this is an ugly workaround, you cannot pass regular integers to gradio functions, so i had to do it this way
|
91 |
-
def bot0(history,
|
92 |
-
bot_message =
|
93 |
history[-1][1] = bot_message
|
94 |
return history
|
95 |
|
96 |
-
def bot1(history,
|
97 |
-
bot_message =
|
98 |
history[-1][1] = bot_message
|
99 |
return history
|
100 |
|
101 |
-
def bot2(history,
|
102 |
-
bot_message =
|
103 |
history[-1][1] = bot_message
|
104 |
return history
|
105 |
|
106 |
-
def bot3(history,
|
107 |
-
bot_message =
|
108 |
history[-1][1] = bot_message
|
109 |
return history
|
110 |
|
111 |
-
def bot4(history,
|
112 |
-
bot_message =
|
113 |
history[-1][1] = bot_message
|
114 |
return history
|
115 |
|
116 |
-
def
|
117 |
-
if
|
118 |
-
|
119 |
-
|
120 |
message_history = [
|
121 |
-
{"role": "system", "content":
|
122 |
]
|
123 |
for pair in history:
|
124 |
message_history.append({"role": "user", "content": pair[0]})
|
@@ -133,55 +133,72 @@ with gr.Blocks(theme=theme, css=css) as iface:
|
|
133 |
else:
|
134 |
return "--- YOU'VE RUN OUT OF QUESTIONS, MAKE YOUR CHOICE ---"
|
135 |
|
136 |
-
def
|
137 |
-
|
138 |
-
if
|
139 |
-
|
140 |
-
return str(
|
141 |
|
142 |
-
def
|
143 |
-
|
144 |
-
return
|
145 |
|
146 |
-
def
|
147 |
return {solvingRow: gr.update(visible=True)}
|
148 |
-
|
|
|
149 |
return {mapRow: gr.update(visible=True)}
|
150 |
-
|
|
|
151 |
return {solvingRow: gr.update(visible=False)}
|
152 |
-
|
|
|
153 |
return {mapRow: gr.update(visible=False)}
|
154 |
|
155 |
-
def
|
156 |
-
return {
|
|
|
|
|
|
|
|
|
157 |
|
158 |
-
def
|
159 |
return "You failed! The real culprit got away... "
|
160 |
|
161 |
-
def
|
162 |
return "Congratulations, you found the killer! "
|
163 |
|
164 |
-
|
165 |
i = 0
|
166 |
while i < len(roles):
|
167 |
-
msg[i].submit(
|
168 |
-
|
169 |
).then(
|
170 |
-
|
|
|
|
|
171 |
)
|
172 |
i += 1
|
173 |
|
174 |
-
mapButton.click(
|
175 |
-
closeMapButton.click(
|
176 |
-
finishButton.click(
|
177 |
-
closeSolvingButton.click(
|
178 |
|
179 |
i = 0
|
180 |
while i < len(roles):
|
181 |
if i == culpritId:
|
182 |
-
accusationButtons[i].click(
|
|
|
|
|
|
|
|
|
183 |
else:
|
184 |
-
accusationButtons[i].click(
|
|
|
|
|
|
|
|
|
185 |
i += 1
|
186 |
|
187 |
iface.launch()
|
|
|
88 |
return "", history + [[user_message, None]]
|
89 |
|
90 |
# this is an ugly workaround, you cannot pass regular integers to gradio functions, so i had to do it this way
|
91 |
+
def bot0(history, question_counter_text):
|
92 |
+
bot_message = generate_ai_message(history, question_counter_text, 0)
|
93 |
history[-1][1] = bot_message
|
94 |
return history
|
95 |
|
96 |
+
def bot1(history, question_counter_text):
|
97 |
+
bot_message = generate_ai_message(history, question_counter_text, 1)
|
98 |
history[-1][1] = bot_message
|
99 |
return history
|
100 |
|
101 |
+
def bot2(history, question_counter_text):
|
102 |
+
bot_message = generate_ai_message(history, question_counter_text, 2)
|
103 |
history[-1][1] = bot_message
|
104 |
return history
|
105 |
|
106 |
+
def bot3(history, question_counter_text):
|
107 |
+
bot_message = generate_ai_message(history, question_counter_text, 3)
|
108 |
history[-1][1] = bot_message
|
109 |
return history
|
110 |
|
111 |
+
def bot4(history, question_counter_text):
|
112 |
+
bot_message = generate_ai_message(history, question_counter_text, 4)
|
113 |
history[-1][1] = bot_message
|
114 |
return history
|
115 |
|
116 |
+
def generate_ai_message(history, question_counter_text, character_id):
|
117 |
+
if check_if_questions_left(question_counter_text):
|
118 |
+
init_sys_message = initText[character_id] + "Stay in character. Use natural language. Don't reveal all of" \
|
119 |
+
" the information in a single message, and leave hints."
|
120 |
message_history = [
|
121 |
+
{"role": "system", "content": init_sys_message}
|
122 |
]
|
123 |
for pair in history:
|
124 |
message_history.append({"role": "user", "content": pair[0]})
|
|
|
133 |
else:
|
134 |
return "--- YOU'VE RUN OUT OF QUESTIONS, MAKE YOUR CHOICE ---"
|
135 |
|
136 |
+
def update_questions(question_counter_text):
|
137 |
+
remaining_questions = int(question_counter_text["label"])
|
138 |
+
if remaining_questions > 0:
|
139 |
+
remaining_questions -= 1
|
140 |
+
return str(remaining_questions)
|
141 |
|
142 |
+
def check_if_questions_left(question_counter_text):
|
143 |
+
remaining_questions = int(question_counter_text["label"])
|
144 |
+
return remaining_questions > 0
|
145 |
|
146 |
+
def try_to_solve():
|
147 |
return {solvingRow: gr.update(visible=True)}
|
148 |
+
|
149 |
+
def show_map():
|
150 |
return {mapRow: gr.update(visible=True)}
|
151 |
+
|
152 |
+
def hide_solve_box():
|
153 |
return {solvingRow: gr.update(visible=False)}
|
154 |
+
|
155 |
+
def hide_map():
|
156 |
return {mapRow: gr.update(visible=False)}
|
157 |
|
158 |
+
def show_result():
|
159 |
+
return {
|
160 |
+
chatRow: gr.update(visible=False),
|
161 |
+
solvingRow: gr.update(visible=False),
|
162 |
+
resultRow: gr.update(visible=True)
|
163 |
+
}
|
164 |
|
165 |
+
def declare_loss():
|
166 |
return "You failed! The real culprit got away... "
|
167 |
|
168 |
+
def declare_victory():
|
169 |
return "Congratulations, you found the killer! "
|
170 |
|
171 |
+
bot_functions = [bot0, bot1, bot2, bot3, bot4]
|
172 |
i = 0
|
173 |
while i < len(roles):
|
174 |
+
msg[i].submit(
|
175 |
+
user, [msg[i], chatbot[i]], [msg[i], chatbot[i]], queue=False
|
176 |
).then(
|
177 |
+
bot_functions[i], [chatbot[i], questionCounter], chatbot[i]
|
178 |
+
).then(
|
179 |
+
update_questions, questionCounter, questionCounter
|
180 |
)
|
181 |
i += 1
|
182 |
|
183 |
+
mapButton.click(show_map, None, mapRow)
|
184 |
+
closeMapButton.click(hide_map, None, mapRow)
|
185 |
+
finishButton.click(try_to_solve, None, solvingRow)
|
186 |
+
closeSolvingButton.click(hide_solve_box, None, solvingRow)
|
187 |
|
188 |
i = 0
|
189 |
while i < len(roles):
|
190 |
if i == culpritId:
|
191 |
+
accusationButtons[i].click(
|
192 |
+
show_result, None, [chatRow, solvingRow, resultRow]
|
193 |
+
).then(
|
194 |
+
declare_victory, None, resultLabel
|
195 |
+
)
|
196 |
else:
|
197 |
+
accusationButtons[i].click(
|
198 |
+
show_result, None, [chatRow, solvingRow, resultRow]
|
199 |
+
).then(
|
200 |
+
declare_loss, None, resultLabel
|
201 |
+
)
|
202 |
i += 1
|
203 |
|
204 |
iface.launch()
|