Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -104,28 +104,28 @@ def gen(input):
|
|
104 |
out = remove_caseifer(generated_text)
|
105 |
return input + out
|
106 |
|
107 |
-
|
108 |
-
def chatbot_func(user_message, history):
|
109 |
-
history = history + [[user_message, None]]
|
110 |
-
bot_message = gen(user_message)
|
111 |
-
|
112 |
-
for character in bot_message:
|
113 |
-
history[-1][1] += character
|
114 |
-
time.sleep(0.05)
|
115 |
-
|
116 |
-
return history
|
117 |
-
|
118 |
-
def clear_chatbot(clear, history):
|
119 |
-
return [] if clear else history
|
120 |
-
|
121 |
with gr.Blocks() as demo:
|
122 |
-
chatbot = gr.Chatbot(
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
demo.launch()
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
104 |
out = remove_caseifer(generated_text)
|
105 |
return input + out
|
106 |
|
107 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
with gr.Blocks() as demo:
|
109 |
+
chatbot = gr.Chatbot()
|
110 |
+
msg = gr.Textbox()
|
111 |
+
clear = gr.Button("Clear")
|
112 |
+
|
113 |
+
def user(user_message, history):
|
114 |
+
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
115 |
+
|
116 |
+
def bot(history):
|
117 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
118 |
+
history[-1][1] = ""
|
119 |
+
for character in bot_message:
|
120 |
+
history[-1][1] += character
|
121 |
+
time.sleep(0.05)
|
122 |
+
yield history
|
123 |
+
|
124 |
+
response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
125 |
+
bot, chatbot, chatbot
|
126 |
+
)
|
127 |
+
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
128 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
129 |
+
|
130 |
+
demo.queue()
|
131 |
demo.launch()
|
|
|
|
|
|