Spaces:
Sleeping
Sleeping
Jonas Wiesli
commited on
Commit
•
39193db
1
Parent(s):
54f7f86
add result row
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ with gr.Blocks() as iface:
|
|
8 |
chatbot = []
|
9 |
msg = []
|
10 |
accusationButtons = []
|
|
|
11 |
roles = ["Security Guard", "Curator", "Researcher", "Conservationist", "Tour Guide"]
|
12 |
initText = ["You are Steve Binner, 31, a security guard for a museum of medieval "
|
13 |
"history. You're absolutely sure that this place is haunted. A month ago, "
|
@@ -45,7 +46,7 @@ with gr.Blocks() as iface:
|
|
45 |
"detective. You use formal language and are very well educated in history, especially medieval "
|
46 |
"history. You have a bubbly personality. "]
|
47 |
|
48 |
-
with gr.Row():
|
49 |
with gr.Column(scale=2):
|
50 |
questionCounter = gr.Label(label="Remaining Questions", value="24")
|
51 |
finishButton = gr.Button("Try to Solve")
|
@@ -61,13 +62,18 @@ with gr.Blocks() as iface:
|
|
61 |
characterImage = gr.Label(label="")
|
62 |
i += 1
|
63 |
|
64 |
-
with gr.Row(visible=False) as
|
65 |
i = 0
|
66 |
while i < len(roles):
|
67 |
-
with gr.Column(
|
68 |
accusationButtons.append(gr.Button(roles[i]))
|
69 |
i += 1
|
70 |
|
|
|
|
|
|
|
|
|
|
|
71 |
def user(user_message, history):
|
72 |
return "", history + [[user_message, None]]
|
73 |
|
@@ -128,8 +134,16 @@ with gr.Blocks() as iface:
|
|
128 |
return remainingQuestions > 0
|
129 |
|
130 |
def tryToSolve():
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
# again, ugly workaround
|
135 |
msg[0].submit(user, [msg[0], chatbot[0]], [msg[0], chatbot[0]], queue=False).then(
|
@@ -162,7 +176,14 @@ with gr.Blocks() as iface:
|
|
162 |
updateQuestions, questionCounter, questionCounter
|
163 |
)
|
164 |
|
165 |
-
finishButton.click(tryToSolve, None,
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
iface.launch()
|
|
|
8 |
chatbot = []
|
9 |
msg = []
|
10 |
accusationButtons = []
|
11 |
+
culpritId = 1
|
12 |
roles = ["Security Guard", "Curator", "Researcher", "Conservationist", "Tour Guide"]
|
13 |
initText = ["You are Steve Binner, 31, a security guard for a museum of medieval "
|
14 |
"history. You're absolutely sure that this place is haunted. A month ago, "
|
|
|
46 |
"detective. You use formal language and are very well educated in history, especially medieval "
|
47 |
"history. You have a bubbly personality. "]
|
48 |
|
49 |
+
with gr.Row() as chatRow:
|
50 |
with gr.Column(scale=2):
|
51 |
questionCounter = gr.Label(label="Remaining Questions", value="24")
|
52 |
finishButton = gr.Button("Try to Solve")
|
|
|
62 |
characterImage = gr.Label(label="")
|
63 |
i += 1
|
64 |
|
65 |
+
with gr.Row(visible=False) as solvingRow:
|
66 |
i = 0
|
67 |
while i < len(roles):
|
68 |
+
with gr.Column():
|
69 |
accusationButtons.append(gr.Button(roles[i]))
|
70 |
i += 1
|
71 |
|
72 |
+
with gr.Row(visible=False) as resultRow:
|
73 |
+
with gr.Column():
|
74 |
+
resultLabel = gr.Label(label="Result")
|
75 |
+
|
76 |
+
|
77 |
def user(user_message, history):
|
78 |
return "", history + [[user_message, None]]
|
79 |
|
|
|
134 |
return remainingQuestions > 0
|
135 |
|
136 |
def tryToSolve():
|
137 |
+
return {solvingRow: gr.update(visible=True)}
|
138 |
+
|
139 |
+
def showResult():
|
140 |
+
return {chatRow: gr.update(visible=False), solvingRow: gr.update(visible=False), resultRow: gr.update(visible=True)}
|
141 |
+
|
142 |
+
def declareLoss():
|
143 |
+
return "You failed! The real culprit got away... "
|
144 |
+
|
145 |
+
def declareVictory():
|
146 |
+
return "Congratulations, you found the killer! "
|
147 |
|
148 |
# again, ugly workaround
|
149 |
msg[0].submit(user, [msg[0], chatbot[0]], [msg[0], chatbot[0]], queue=False).then(
|
|
|
176 |
updateQuestions, questionCounter, questionCounter
|
177 |
)
|
178 |
|
179 |
+
finishButton.click(tryToSolve, None, solvingRow)
|
180 |
|
181 |
+
i = 0
|
182 |
+
while i < len(roles):
|
183 |
+
if i == culpritId:
|
184 |
+
accusationButtons[i].click(showResult, None, [chatRow, solvingRow, resultRow]).then(declareVictory, None, resultLabel)
|
185 |
+
else:
|
186 |
+
accusationButtons[i].click(showResult, None, [chatRow, solvingRow, resultRow]).then(declareLoss, None, resultLabel)
|
187 |
+
i += 1
|
188 |
|
189 |
iface.launch()
|