Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -41,13 +41,30 @@ with gr.Blocks(css = "custom.css") as demo:
|
|
41 |
def user(user_message, history):
|
42 |
return "", history + [[user_message, None]]
|
43 |
|
44 |
-
def bot_api(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
history[-1][1] = ""
|
46 |
-
|
47 |
-
pred_iter = predict(
|
48 |
for ele in pred_iter:
|
49 |
history[-1][1] = ele
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
def bot(history):
|
53 |
'''
|
@@ -80,6 +97,7 @@ with gr.Blocks(css = "custom.css") as demo:
|
|
80 |
interactive=True,
|
81 |
#info = "Generate by Click, and can edit by yourself, look up Examples below"
|
82 |
)
|
|
|
83 |
sub_button = gr.Button("Submit")
|
84 |
clear = gr.Button("Clear")
|
85 |
api_button = gr.Button("api", visible = False)
|
@@ -89,7 +107,7 @@ with gr.Blocks(css = "custom.css") as demo:
|
|
89 |
)
|
90 |
|
91 |
api_button.click(
|
92 |
-
bot_api,
|
93 |
)
|
94 |
|
95 |
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
41 |
def user(user_message, history):
|
42 |
return "", history + [[user_message, None]]
|
43 |
|
44 |
+
def bot_api(user_message):
|
45 |
+
l = user_message.split("[SEP]")
|
46 |
+
history = []
|
47 |
+
for ele in history:
|
48 |
+
if not history:
|
49 |
+
history.append(
|
50 |
+
[ele]
|
51 |
+
)
|
52 |
+
else:
|
53 |
+
if len(history[-1]) == 2:
|
54 |
+
history.append([ele])
|
55 |
+
else:
|
56 |
+
history[-1].append(ele)
|
57 |
history[-1][1] = ""
|
58 |
+
user_message_ = history[-1][0]
|
59 |
+
pred_iter = predict(user_message_ ,history)
|
60 |
for ele in pred_iter:
|
61 |
history[-1][1] = ele
|
62 |
+
user_message_out = []
|
63 |
+
for ele in history:
|
64 |
+
for e in ele:
|
65 |
+
user_message_out.append(e)
|
66 |
+
user_message_out = "[SEP]".join(user_message_out)
|
67 |
+
return user_message_out
|
68 |
|
69 |
def bot(history):
|
70 |
'''
|
|
|
97 |
interactive=True,
|
98 |
#info = "Generate by Click, and can edit by yourself, look up Examples below"
|
99 |
)
|
100 |
+
msg_out = gr.Textbox(visible = False)
|
101 |
sub_button = gr.Button("Submit")
|
102 |
clear = gr.Button("Clear")
|
103 |
api_button = gr.Button("api", visible = False)
|
|
|
107 |
)
|
108 |
|
109 |
api_button.click(
|
110 |
+
bot_api, msg, msg_out
|
111 |
)
|
112 |
|
113 |
clear.click(lambda: None, None, chatbot, queue=False)
|