sklep-internetowy-systemy-d.../chatbot/main.py

36 lines
988 B
Python
Raw Normal View History

2024-05-07 21:40:14 +02:00
from pathlib import Path
from modules.nlp import NaturalLanguageProcessor
from modules.generator import ResponseGenerator
from modules.config import Config
2024-05-05 21:42:45 +02:00
import colorama
from colorama import Fore, Style
colorama.init(autoreset=True)
2024-05-07 21:40:14 +02:00
def main():
base_path = Path(__file__).resolve().parent
config_path = base_path / 'config' / 'config.json'
config = Config.load_config(config_path)
2024-05-05 21:42:45 +02:00
nlp = NaturalLanguageProcessor(config)
2024-05-07 21:40:14 +02:00
generator = ResponseGenerator(config)
print(Fore.CYAN + "Witaj w chatbocie! Rozpocznij rozmowę.")
2024-05-05 21:42:45 +02:00
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
2024-05-07 21:40:14 +02:00
intent = nlp.analyze(user_input)
response = generator.generate(intent)
2024-05-07 23:14:14 +02:00
2024-05-07 21:40:14 +02:00
print(Fore.CYAN + "Bot: " + response)
if __name__ == "__main__":
main()