gunthercox / ChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots
https://chatterbot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
14.02k stars 4.43k forks source link

Help a newbee please. #2209

Closed GabrielMendesdc closed 2 years ago

GabrielMendesdc commented 2 years ago

Hi, im a very newbee dev, im working in a wpp bot,


`OSError                                   Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_1864/3484406297.py in <module>
     93 conv = ['oi','olá','Tudo bem?','Estou bem!','O que você gosta de fazer?','Gosto de estudar Python e você?']
     94 #No método train do Chatterbot o mesmo é treinado.
---> 95 botzin = wppbot('oi')
     96 botzin.treina(conv)

~\AppData\Local\Temp/ipykernel_1864/3484406297.py in __init__(self, nome_bot)
     14     def __init__(self, nome_bot):
     15 #Setamos nosso bot e a forma que ele irá treinar.
---> 16         self.bot = ChatBot(nome_bot)
     17         self.bot.set_trainer(ListTrainer)
     18 #Setamos onde está nosso chromedriver.

~\anaconda3\envs\chatbot\lib\site-packages\chatterbot\chatterbot.py in __init__(self, name, **kwargs)
     26         self.logic_adapters = []
     27 
---> 28         self.storage = utils.initialize_class(storage_adapter, **kwargs)
     29 
     30         primary_search_algorithm = IndexedTextSearch(self, **kwargs)

~\anaconda3\envs\chatbot\lib\site-packages\chatterbot\utils.py in initialize_class(data, *args, **kwargs)
     31         Class = import_module(data)
     32 
---> 33         return Class(*args, **kwargs)
     34 
     35 

~\anaconda3\envs\chatbot\lib\site-packages\chatterbot\storage\sql_storage.py in __init__(self, **kwargs)
     18 
     19     def __init__(self, **kwargs):
---> 20         super().__init__(**kwargs)
     21 
     22         from sqlalchemy import create_engine

~\anaconda3\envs\chatbot\lib\site-packages\chatterbot\storage\storage_adapter.py in __init__(self, *args, **kwargs)
     19 
     20         self.tagger = PosLemmaTagger(language=kwargs.get(
---> 21             'tagger_language', languages.ENG
     22         ))
     23 

~\anaconda3\envs\chatbot\lib\site-packages\chatterbot\tagging.py in __init__(self, language)
     11         self.punctuation_table = str.maketrans(dict.fromkeys(string.punctuation))
     12 
---> 13         self.nlp = spacy.load(self.language.ISO_639_1.lower())
     14 
     15     def get_bigram_pair_string(self, text):

~\anaconda3\envs\chatbot\lib\site-packages\spacy\__init__.py in load(name, **overrides)
     19     if depr_path not in (True, False, None):
     20         deprecation_warning(Warnings.W001.format(path=depr_path))
---> 21     return util.load_model(name, **overrides)
     22 
     23 

~\anaconda3\envs\chatbot\lib\site-packages\spacy\util.py in load_model(name, **overrides)
    117     elif hasattr(name, 'exists'):  # Path or Path-like to model data
    118         return load_model_from_path(name, **overrides)
--> 119     raise IOError(Errors.E050.format(name=name))
    120 
    121 

OSError: [E050] Can't find model 'en'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.`

im getting this error when creating a class and defining my bots name, im doing something wrong?


`import os 
import time
import re
from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
from selenium import webdriver
class wppbot:
    dir_path = os.getcwd()
    def __init__(self, nome_bot):
        self.bot = ChatBot(nome_bot)
        self.bot.set_trainer(ListTrainer)
        self.chrome = self.dir_path+'\chromedriver.exe'
        self.options = webdriver.ChromeOptions()
        self.options.add_argument(r"user-data-dir="+self.dir_path+"\profile\wpp")
        self.driver = webdriver.Chrome(self.chrome, chrome_options=self.options)

    def inicia(self,nome_contato):
        self.driver.get('https://web.whatsapp.com/')
        self.driver.implicitly_wait(15)
        self.caixa_de_pesquisa = self.driver.find_element_by_class_name('jN-F5')
        self.caixa_de_pesquisa.send_keys(nome_contato)
        time.sleep(2)
        self.contato = self.driver.find_element_by_xpath('//span[@title = "{}"]'.format(nome_contato))
        self.contato.click()
        time.sleep(2)

    def saudacao(self,frase_inicial):
        self.caixa_de_mensagem = self.driver.find_element_by_class_name('_2S1VP')
        if type(frase_inicial) == list:
            for frase in frase_inicial:
                self.caixa_de_mensagem.send_keys(frase)
                time.sleep(1)
                self.botao_enviar = self.driver.find_element_by_class_name('_35EW6')
                self.botao_enviar.click()
                time.sleep(1)
        else:
            return False

    def escuta(self):
        post = self.driver.find_elements_by_class_name('_3_7SH')
        ultimo = len(post) - 1
        texto = post[ultimo].find_element_by_css_selector('span.selectable-text').text
        return texto

    def responde(self,texto):
        response = self.bot.get_response(texto)
        response = str(response)
        response = 'bot: ' + response
        self.caixa_de_mensagem = self.driver.find_element_by_class_name('_2S1VP')
        self.caixa_de_mensagem.send_keys(response)
        time.sleep(1)
        self.botao_enviar = self.driver.find_element_by_class_name('_35EW6')
        self.botao_enviar.click()

    def treina(self,nome_pasta):
        for treino in os.listdir(nome_pasta):
            conversas = open(nome_pasta+'/'+treino, 'r').readlines()
            self.bot.train(conversas)

conv = ['oi','olá','Tudo bem?','Estou bem!','O que você gosta de fazer?','Gosto de estudar Python e você?']
botzin = wppbot('oi')
botzin.treina(conv)`

sorry for take your time, i hope it isnt a dumby issue. thanks for atention

Diego448 commented 2 years ago

There are few workarounds for it, so please review this issue that is the fastest and easiest way to solve your problem