Skip to content

Commit

Permalink
Add version checking and fix AttributeError on older chatterbot versi…
Browse files Browse the repository at this point in the history
…on 1.0.5 vs 1.10
  • Loading branch information
srevinsaju committed Apr 7, 2020
1 parent a8fe841 commit 260c0c6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Sugaroid
[![Become a Patron](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/srevinsaju?fan_landing=true)

> **IMPORTANT** : Sugaroid is an open source software. The web server is deployed on Heroku on a free tier. So far, the heroku server has a RAM of 512 MB which is not enough for both web preview and chatbot deploy. Your support for this open source software is highly necessary to make this project continued to be served on the world wide web. Consider being my patron to help Sugaroid host its servers or if you are willing to lend servers for Sugaroid, press the sponsor button and email me. Thanks. However, Sugaroid will always remain free forever :smile:
> **IMPORTANT** : Sugaroid is an open source software. The web server is deployed on Microsoft Azure. Your support for this open source software is highly necessary to make this project continued to be served on the world wide web. Consider being my patron to help Sugaroid host its servers or if you are willing to lend servers for Sugaroid, press the sponsor button and email me. Thanks. However, Sugaroid will always remain free forever :smile:
## Introduction

Expand Down
10 changes: 8 additions & 2 deletions sugaroid/sugaroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,16 @@ def get_response(self, statement=None, **kwargs):
# Make sure the input statement has its search text saved

if not input_statement.search_text:
input_statement.search_text = self.storage.tagger.get_text_index_string(input_statement.text)
try:
input_statement.search_text = self.storage.tagger.get_text_index_string(input_statement.text)
except AttributeError:
input_statement.search_text = self.storage.tagger.get_bigram_pair_string(input_statement.text)

if not input_statement.search_in_response_to and input_statement.in_response_to:
input_statement.search_in_response_to = self.storage.tagger.get_text_index_string(input_statement.in_response_to)
try:
input_statement.search_in_response_to = self.storage.tagger.get_text_index_string(input_statement.in_response_to)
except AttributeError:
input_statement.search_in_response_to = self.storage.tagger.get_bigram_pair_string(input_statement.in_response_to)

response = self.generate_response(input_statement, additional_response_selection_parameters)

Expand Down
22 changes: 22 additions & 0 deletions sugaroid/web/websugaroid/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,25 @@ wikipedia-api
mediawikiapi
sugaroid-chatterbot
sugaroid-chatterbot-corpus
wikipedia-API
pyyaml
newsapi-python
sugaroid-chatterbot
pyjokes
pyspellchecker
python-dotenv
nltk
sugaroid-chatterbot-corpus
freegames
spacy
requests
lxml
beautifulsoup4
django-googlesearch
scikit-learn
googletrans
wikipedia
akinator.py
emoji
pyinflect
currencyconverter
22 changes: 11 additions & 11 deletions sugaroid/web/websugaroid/sugaroid_chatbot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ def post_user_input(request):
def get_chatbot_response(request):
print("D"*5, "K"*6, request.COOKIES.get('conversation'))
conversation_local = eval(request.COOKIES.get('conversation'))
try:
conv = sg.parse(conversation_local[-1][1])
r = emojize(str(conv))
r = r.encode('ascii', 'ignore').decode()
emotion = conv.emotion
conversation_local.append(['sent', r, emotion])
response = HttpResponseRedirect('/')
response.set_cookie('conversation', '{}'.format(conversation_local))
return response
except Exception as e:
return error_404(request, str(e))
# try:
conv = sg.parse(conversation_local[-1][1])
r = emojize(str(conv))
r = r.encode('ascii', 'ignore').decode()
emotion = conv.emotion
conversation_local.append(['sent', r, emotion])
response = HttpResponseRedirect('/')
response.set_cookie('conversation', '{}'.format(conversation_local))
return response
#except Exception as e:
# return error_404(request, str(e))


def error_404(request, error=""):
Expand Down
4 changes: 2 additions & 2 deletions sugaroid/web/websugaroid/templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<h1>Error 500</h1>
<h2>Ouch. I just fell into a pit.</h2>
<p>I am still under testing purposes. I easily make mistakes.</p>
<a href="https://sugaroid.herokuapp.com"><p>Try again!</p></a>
<a href="https://sugaroid.azurewebsites.net"><p>Try again!</p></a>
<p>If at first you don't succeed. Refresh! Refresh! and Refresh again!</p>
<p>Try clearing your cookies too.</p>
</div>
Expand All @@ -40,4 +40,4 @@ <h2>Ouch. I just fell into a pit.</h2>

</body>

</html>
</html>
8 changes: 4 additions & 4 deletions sugaroid/web/websugaroid/websugaroid/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
path('user', post_user_input),
path('chatbot', get_chatbot_response)
]
handler404 = 'sugaroid_chatbot.views.error_404'
handler500 = 'sugaroid_chatbot.views.error_404'
handler403 = 'sugaroid_chatbot.views.error_404'
handler400 = 'sugaroid_chatbot.views.error_404'
#handler404 = 'sugaroid_chatbot.views.error_404'
#handler500 = 'sugaroid_chatbot.views.error_404'
#handler403 = 'sugaroid_chatbot.views.error_404'
#handler400 = 'sugaroid_chatbot.views.error_404'

0 comments on commit 260c0c6

Please sign in to comment.