sklep-internetowy-systemy-d.../chatbot/main.py
2024-05-05 21:42:45 +02:00

33 lines
1.1 KiB
Python

from modules.nlp import NaturalLanguageProcessor, Config
from modules.state_monitor import DialogueStateMonitor
from modules.strategy import DialogueStrategy
from modules.generator import NaturalLanguageGenerator
import colorama
from colorama import Fore, Style
colorama.init(autoreset=True)
def chatbot_response(input_text: str, nlp: NaturalLanguageProcessor) -> str:
dialogue_monitor = DialogueStateMonitor()
analysis = nlp.analyze(input_text)
dialogue_monitor.update_state(analysis['intent'])
response = DialogueStrategy.decide_response(dialogue_monitor.state)
final_response = NaturalLanguageGenerator.generate(response)
return final_response
if __name__ == "__main__":
config = Config()
nlp = NaturalLanguageProcessor(config)
print(Fore.YELLOW + "Wpisz 'quit' aby zakończyć program.\n")
while True:
user_input = input(Fore.GREEN + "Ty: " + Style.RESET_ALL)
if user_input.lower() == "quit":
print(Fore.RED + "Zamykanie chatbota...")
break
print(Fore.CYAN + "Bot: " + chatbot_response(user_input, nlp))