Spaces:
Sleeping
Sleeping
Jonas Wiesli
commited on
Commit
•
64a8d23
1
Parent(s):
4cfce75
add solving box
Browse files
app.py
CHANGED
@@ -54,43 +54,50 @@ with gr.Blocks() as iface:
|
|
54 |
with gr.Tab(roles[i]):
|
55 |
with gr.Row():
|
56 |
with gr.Column(scale=9):
|
57 |
-
chatbot.append(gr.Chatbot())
|
58 |
-
msg.append(gr.Textbox())
|
59 |
with gr.Column(scale=3):
|
60 |
-
characterImage = gr.Label()
|
61 |
i += 1
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
def user(user_message, history):
|
64 |
return "", history + [[user_message, None]]
|
65 |
|
66 |
# this is an ugly workaround, you cannot pass regular integers to gradio functions, so i had to do it this way
|
67 |
-
def bot0(history,
|
68 |
-
bot_message = generateAIMessage(history,
|
69 |
history[-1][1] = bot_message
|
70 |
return history
|
71 |
|
72 |
-
def bot1(history,
|
73 |
-
bot_message = generateAIMessage(history,
|
74 |
history[-1][1] = bot_message
|
75 |
return history
|
76 |
|
77 |
-
def bot2(history,
|
78 |
-
bot_message = generateAIMessage(history,
|
79 |
history[-1][1] = bot_message
|
80 |
return history
|
81 |
|
82 |
-
def bot3(history,
|
83 |
-
bot_message = generateAIMessage(history,
|
84 |
history[-1][1] = bot_message
|
85 |
return history
|
86 |
|
87 |
-
def bot4(history,
|
88 |
-
bot_message = generateAIMessage(history,
|
89 |
history[-1][1] = bot_message
|
90 |
return history
|
91 |
|
92 |
-
def generateAIMessage(history,
|
93 |
-
if checkIfQuestionsLeft(
|
94 |
message_history = [
|
95 |
{"role": "system", "content": initText[characterId] + "Stay in character. Use natural language. Don't "
|
96 |
"reveal all of the information in a single "
|
@@ -109,16 +116,19 @@ with gr.Blocks() as iface:
|
|
109 |
else:
|
110 |
return "--- YOU'VE RUN OUT OF QUESTIONS, MAKE YOUR CHOICE ---"
|
111 |
|
112 |
-
def updateQuestions(
|
113 |
-
remainingQuestions = int(
|
114 |
if remainingQuestions > 0:
|
115 |
remainingQuestions -= 1
|
116 |
return "Remaining Questions: " + str(remainingQuestions)
|
117 |
|
118 |
-
def checkIfQuestionsLeft(
|
119 |
-
remainingQuestions = int(
|
120 |
return remainingQuestions > 0
|
121 |
|
|
|
|
|
|
|
122 |
# again, ugly workaround
|
123 |
msg[0].submit(user, [msg[0], chatbot[0]], [msg[0], chatbot[0]], queue=False).then(
|
124 |
bot0, [chatbot[0], questionCounter], chatbot[0]
|
@@ -150,5 +160,7 @@ with gr.Blocks() as iface:
|
|
150 |
updateQuestions, questionCounter, questionCounter
|
151 |
)
|
152 |
|
|
|
|
|
153 |
|
154 |
iface.launch()
|
|
|
54 |
with gr.Tab(roles[i]):
|
55 |
with gr.Row():
|
56 |
with gr.Column(scale=9):
|
57 |
+
chatbot.append(gr.Chatbot(label=roles[i]))
|
58 |
+
msg.append(gr.Textbox(label=""))
|
59 |
with gr.Column(scale=3):
|
60 |
+
characterImage = gr.Label(label="")
|
61 |
i += 1
|
62 |
|
63 |
+
with gr.Row(visible="false") as solvingBox:
|
64 |
+
i = 0
|
65 |
+
while i < len(roles):
|
66 |
+
with gr.Column():
|
67 |
+
finishButton = gr.Button(roles[i])
|
68 |
+
i += 1
|
69 |
+
|
70 |
def user(user_message, history):
|
71 |
return "", history + [[user_message, None]]
|
72 |
|
73 |
# this is an ugly workaround, you cannot pass regular integers to gradio functions, so i had to do it this way
|
74 |
+
def bot0(history, questionCounterText):
|
75 |
+
bot_message = generateAIMessage(history, questionCounterText, 0)
|
76 |
history[-1][1] = bot_message
|
77 |
return history
|
78 |
|
79 |
+
def bot1(history, questionCounterText):
|
80 |
+
bot_message = generateAIMessage(history, questionCounterText, 1)
|
81 |
history[-1][1] = bot_message
|
82 |
return history
|
83 |
|
84 |
+
def bot2(history, questionCounterText):
|
85 |
+
bot_message = generateAIMessage(history, questionCounterText, 2)
|
86 |
history[-1][1] = bot_message
|
87 |
return history
|
88 |
|
89 |
+
def bot3(history, questionCounterText):
|
90 |
+
bot_message = generateAIMessage(history, questionCounterText, 3)
|
91 |
history[-1][1] = bot_message
|
92 |
return history
|
93 |
|
94 |
+
def bot4(history, questionCounterText):
|
95 |
+
bot_message = generateAIMessage(history, questionCounterText, 4)
|
96 |
history[-1][1] = bot_message
|
97 |
return history
|
98 |
|
99 |
+
def generateAIMessage(history, questionCounterText, characterId):
|
100 |
+
if checkIfQuestionsLeft(questionCounterText):
|
101 |
message_history = [
|
102 |
{"role": "system", "content": initText[characterId] + "Stay in character. Use natural language. Don't "
|
103 |
"reveal all of the information in a single "
|
|
|
116 |
else:
|
117 |
return "--- YOU'VE RUN OUT OF QUESTIONS, MAKE YOUR CHOICE ---"
|
118 |
|
119 |
+
def updateQuestions(questionCounterText):
|
120 |
+
remainingQuestions = int(questionCounterText["label"].split(": ")[1])
|
121 |
if remainingQuestions > 0:
|
122 |
remainingQuestions -= 1
|
123 |
return "Remaining Questions: " + str(remainingQuestions)
|
124 |
|
125 |
+
def checkIfQuestionsLeft(questionCounterText):
|
126 |
+
remainingQuestions = int(questionCounterText["label"].split(": ")[1])
|
127 |
return remainingQuestions > 0
|
128 |
|
129 |
+
def tryToSolve():
|
130 |
+
return {solvingBox: gr.update(visible=True)}
|
131 |
+
|
132 |
# again, ugly workaround
|
133 |
msg[0].submit(user, [msg[0], chatbot[0]], [msg[0], chatbot[0]], queue=False).then(
|
134 |
bot0, [chatbot[0], questionCounter], chatbot[0]
|
|
|
160 |
updateQuestions, questionCounter, questionCounter
|
161 |
)
|
162 |
|
163 |
+
finishButton.click(tryToSolve, None, solvingBox)
|
164 |
+
|
165 |
|
166 |
iface.launch()
|