简体   繁体   English

AttributeError:模块'__main__'没有属性'cleaner'

[英]AttributeError: module '__main__' has no attribute 'cleaner'

We are creating web-site with ai assistant.我们正在使用人工智能助手创建网站。 We trained our model in Google Colab and now we are trying to upload it to our project.我们在 Google Colab 中训练了 model,现在我们正在尝试将其上传到我们的项目中。 But we get the following error:但是我们得到以下错误:

AttributeError: module '__main__' has no attribute 'cleaner'

In our file views.py declared the class VoiceAssistant and the function cleaner for pipeline.在我们的文件views.py中声明了 class VoiceAssistant和 function cleaner用于管道。 The problem is hidden on the line:问题隐藏就行了:

talk_model = joblib.load(r'artifitial_assistant/model.pkl')

While training our model we used the following code:在训练我们的 model 时,我们使用了以下代码:

Pipeline(steps=[('bow',
                 CountVectorizer(analyzer = cleaner)),
                ('tfidf', TfidfTransformer()),
                ('classifier', DecisionTreeClassifier())])

Views.py:视图.py:

import string
import traceback
import webbrowser
import joblib
import pyttsx3
import speech_recognition
import wikipedia
from django.shortcut import render


def cleaner(x):
    """
    cleaning function required for neural model
    """
    return [a for a in (''.join([a for a in x if a not in string.punctuation])).lower().split()]


class VoiceAssistant:
    """
    Settings of our voice assistant
    """
    name = ""
    sex = ""
    speech_lang = ""
    is_talking = False
    recognition_lang = ""
    # initializing speech recognition and input tools
    recognizer = speech_recognition.Recognizer()
    microphone = speech_recognition.Microphone()

    # initialization of the speech synthesis tool
    ttsEngine = pyttsx3.init()

    def assistant_answer(self, voice):
        """
        a function that loads user input into the neural model and predicts the response
        """
        answer = self.talk_model.predict([voice])[0]
        return answer


    # loading a neural model from disk
    talk_model = joblib.load(r'artifitial_assistant/model.pkl') # !!!<-Problem uppears here
    
    ... 

    
from django.shortcuts import render
from django.http import HttpResponse

#initializing voice_assistant
voice_assistant = VoiceAssistant()
voice_assistant.sex = "female"
voice_assistant.speech_lang = "en"
voice_assistant.name = "blonde"
voice_assistant.setup_assistant_voice()


def first_view(request): #just want to get the simplest response from voice_assistant
    return HttpResponse(voice_assistant.assistant_answer('Hi'))

To solve this problem, I just added cleaner function to the manage.py, because there is the module main .为了解决这个问题,我只是在manage.py中添加了cleaner function,因为有main模块。 It solved the problem.它解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 模块 '__main__' 没有属性 'AverageWordLengthExtractor' - AttributeError: module '__main__' has no attribute 'AverageWordLengthExtractor' pickle/joblib AttributeError: 模块 &#39;__main__&#39; 在 pytest 中没有属性 &#39;thing&#39; - pickle/joblib AttributeError: module '__main__' has no attribute 'thing' in pytest unittest:AttributeError:模块'__main__'没有属性'C:\ ...' - unittest: AttributeError: module '__main__' has no attribute 'C:\…' TensorFlow:模块&#39;__main__&#39;没有属性&#39;main&#39; - TensorFlow: module '__main__' has no attribute 'main' 查找“pip”的模块规范时出错(AttributeError:模块“__main__”没有属性“__file__”) - Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__') Pydoop mapreduce“ AttributeError:模块&#39;wordcount_minimal&#39;没有属性&#39;__main__&#39;” - Pydoop mapreduce “AttributeError: module 'wordcount_minimal' has no attribute '__main__'” 用于单元测试的python3:AttributeError:模块&#39;__main__&#39;没有属性“内核......” - python3 for unit test: AttributeError: module '__main__' has no attribute “kernel…” Python多处理错误:AttributeError:模块&#39;__main__&#39;没有属性&#39;__spec__&#39; - Python Multiprocessing error: AttributeError: module '__main__' has no attribute '__spec__' AttributeError的: - AttributeError: <module '__main__' from [..] does not have the attribute 'open' AttributeError:无法获取属性“tokenizer”<module '__main__'> - AttributeError: Can't get attribute 'tokenizer' on <module '__main__'>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM