Spaces:
Sleeping
Sleeping
Jonas Wiesli
commited on
Commit
•
288fcab
1
Parent(s):
a05bc4d
implemented ugly workaround
Browse files
app.py
CHANGED
@@ -39,17 +39,29 @@ with gr.Blocks() as iface:
|
|
39 |
def user(user_message, history):
|
40 |
return "", history + [[user_message, None]]
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
def
|
44 |
-
|
45 |
-
j = 0
|
46 |
-
while j < len(chatbot):
|
47 |
-
print(chatbot[j])
|
48 |
-
print(history)
|
49 |
-
if chatbot[j] == history:
|
50 |
-
characterId = j
|
51 |
-
j += 1
|
52 |
-
bot_message = generateAIMessage(history, characterId)
|
53 |
history[-1][1] = bot_message
|
54 |
return history
|
55 |
|
@@ -71,11 +83,21 @@ with gr.Blocks() as iface:
|
|
71 |
)
|
72 |
return completion.choices[0].message.content
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
iface.launch()
|
|
|
39 |
def user(user_message, history):
|
40 |
return "", history + [[user_message, None]]
|
41 |
|
42 |
+
# this is an ugly workaround, you cannot pass regular integers to gradio functions, so i had to do it this way
|
43 |
+
def bot0(history):
|
44 |
+
bot_message = generateAIMessage(history, 0)
|
45 |
+
history[-1][1] = bot_message
|
46 |
+
return history
|
47 |
+
|
48 |
+
def bot1(history):
|
49 |
+
bot_message = generateAIMessage(history, 1)
|
50 |
+
history[-1][1] = bot_message
|
51 |
+
return history
|
52 |
+
|
53 |
+
def bot2(history):
|
54 |
+
bot_message = generateAIMessage(history, 2)
|
55 |
+
history[-1][1] = bot_message
|
56 |
+
return history
|
57 |
+
|
58 |
+
def bot3(history):
|
59 |
+
bot_message = generateAIMessage(history, 3)
|
60 |
+
history[-1][1] = bot_message
|
61 |
+
return history
|
62 |
|
63 |
+
def bot4(history):
|
64 |
+
bot_message = generateAIMessage(history, 4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
history[-1][1] = bot_message
|
66 |
return history
|
67 |
|
|
|
83 |
)
|
84 |
return completion.choices[0].message.content
|
85 |
|
86 |
+
# again, ugly workaround
|
87 |
+
msg[0].submit(user, [msg[0], chatbot[0]], [msg[0], chatbot[0]], queue=False).then(
|
88 |
+
bot0, chatbot[0], chatbot[0]
|
89 |
+
)
|
90 |
+
msg[1].submit(user, [msg[1], chatbot[1]], [msg[1], chatbot[1]], queue=False).then(
|
91 |
+
bot1, chatbot[1], chatbot[1]
|
92 |
+
)
|
93 |
+
msg[2].submit(user, [msg[2], chatbot[2]], [msg[2], chatbot[2]], queue=False).then(
|
94 |
+
bot2, chatbot[2], chatbot[2]
|
95 |
+
)
|
96 |
+
msg[3].submit(user, [msg[3], chatbot[3]], [msg[3], chatbot[3]], queue=False).then(
|
97 |
+
bot3, chatbot[3], chatbot[3]
|
98 |
+
)
|
99 |
+
msg[4].submit(user, [msg[4], chatbot[4]], [msg[4], chatbot[4]], queue=False).then(
|
100 |
+
bot4, chatbot[4], chatbot[4]
|
101 |
+
)
|
102 |
|
103 |
iface.launch()
|