Spaces:
No application file
No application file
Commit
·
f9888bf
1
Parent(s):
4be09ca
Usando o PANEL básico para o ChatBot
Browse files
1_Building_a_basic_ChatBot.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Data Scientist.: Dr. Eddy Giusepe Chirinos Isidro
|
| 3 |
+
|
| 4 |
+
Usando o widget ChatInterface para ecoar uma mensagem
|
| 5 |
+
=====================================================
|
| 6 |
+
Com 'pn.chat.ChatInterface', podemos enviar mensagens para a interface de chat, mas como
|
| 7 |
+
o sistema deve responder? Podemos definir uma função callback! Neste exemplo, nossa
|
| 8 |
+
função callback simplesmente ecoa uma mensagem do usuário.
|
| 9 |
+
|
| 10 |
+
Executando este script
|
| 11 |
+
----------------------
|
| 12 |
+
|
| 13 |
+
$ panel serve 1_Building_a_basic_ChatBot
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
import panel as pn
|
| 17 |
+
|
| 18 |
+
pn.extension()
|
| 19 |
+
|
| 20 |
+
def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
|
| 21 |
+
message = f"Ecoando {user}: {contents}"
|
| 22 |
+
return message
|
| 23 |
+
|
| 24 |
+
chat_interface = pn.chat.ChatInterface(callback=callback, callback_user="System")
|
| 25 |
+
chat_interface.send("Envie uma mensagem para receber um eco!", user="System", respond=False)
|
| 26 |
+
chat_interface.servable()
|