-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
27 lines (22 loc) · 805 Bytes
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from rasa_core.agent import Agent
from rasa_core.interpreter import RasaNLUInterpreter
import time
interpreter = RasaNLUInterpreter('models/current/nlu')
messages = ["Hi! you can chat in this window. Type 'stop' to end the conversation."]
agent = Agent.load('models/dialogue', interpreter=interpreter)
def chatlogs_html(messages):
messages_html = "".join(["<p>{}</p>".format(m) for m in messages])
chatbot_html = """<div class="chat-window" {}</div>""".format(messages_html)
return chatbot_html
while True:
response = chatlogs_html(messages)
print (response)
time.sleep(0.3)
a = input()
messages.append(a)
if a == 'stop':
break
responses = agent.handle_message(a)
#print(responses)
for r in responses:
messages.append(r.get("text"))