-
-
Save LintangWisesa/a80a56fcf1e6526fbf41a370214a4fd8 to your computer and use it in GitHub Desktop.
Chatterbot - Webinar HIMTI UPI YAI - 12 Aug 2023
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Basic Chatterbot | |
# python -m pip install ChatterBot==1.0.4 | |
# pip install ChatterBot==1.0.4 | |
from chatterbot import ChatBot | |
chatbot = ChatBot("Iron Man") | |
exit_text = ("x", "exit", "quit") | |
while True: | |
query = input(" You 🧑 : ") | |
if query in exit_text: | |
break | |
else: | |
print(f" Bot 🤖 : {chatbot.get_response(query)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2. Chatterbot List Trainer | |
from chatterbot import ChatBot | |
from chatterbot.trainers import ListTrainer | |
chatbot = ChatBot("Iron Man") | |
trainer = ListTrainer(chatbot) | |
trainer.train(["Siapa namamu?", "I am Iron Man"]) | |
exit_text = ("x", "exit", "quit") | |
while True: | |
query = input(" You 🧑 : ") | |
if query in exit_text: | |
break | |
else: | |
print(f" Bot 🤖 : {chatbot.get_response(query)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 3. Chatterbot Corpus | |
from chatterbot import ChatBot | |
from chatterbot.trainers import ChatterBotCorpusTrainer | |
chatbot = ChatBot("Iron Man") | |
trainer = ChatterBotCorpusTrainer(chatbot) | |
trainer.train('chatterbot.corpus.indonesia') | |
exit_text = ("x", "exit", "quit") | |
while True: | |
query = input(" You 🧑 : ") | |
if query in exit_text: | |
break | |
else: | |
print(f" Bot 🤖 : {chatbot.get_response(query)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment