ctgadget commited on
Commit
f1ac257
·
1 Parent(s): d021471

changed python file for chatbot demo to 'demo_chatbot' and added some error handling in case the user has required files missing.

Browse files
chatbotlib/{chatbot_demo.py → demo_chatbot.py} RENAMED
@@ -28,12 +28,9 @@ def run_app():
28
  from streamlit_chat import message
29
 
30
  from keras.models import load_model
31
- chatbot_model = load_model('chatbot_model.h5')
32
 
33
- # Load commands and preprocessed data
34
  commands = json.loads(open('commands.json').read())
35
- words = pickle.load(open('words.pkl', 'rb'))
36
- classes = pickle.load(open('classes.pkl', 'rb'))
37
 
38
  ######################################
39
  # :: HELPER FUNCTIONS FOR PROCESSING #
@@ -212,6 +209,26 @@ def run_app():
212
  NLP Chatbot is a conversational chat bot. Begin by entering in a prompt below.
213
  """
214
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  # Explanation of code using st.markdown with bullet points
216
  st.markdown("""
217
  - This chatbot app offers the following options:
 
28
  from streamlit_chat import message
29
 
30
  from keras.models import load_model
 
31
 
32
+ # Load commands
33
  commands = json.loads(open('commands.json').read())
 
 
34
 
35
  ######################################
36
  # :: HELPER FUNCTIONS FOR PROCESSING #
 
209
  NLP Chatbot is a conversational chat bot. Begin by entering in a prompt below.
210
  """
211
  )
212
+
213
+ try:
214
+ # Load preprocessed data and the model
215
+ words = pickle.load(open('words.pkl', 'rb'))
216
+ classes = pickle.load(open('classes.pkl', 'rb'))
217
+ chatbot_model = load_model('chatbot_model.h5')
218
+
219
+ except Exception as e:
220
+ st.error("An error occurred from missing a generated file...")
221
+ st.error(str(e))
222
+ st.info("""
223
+ Double check if you followed all the steps in **Train the Chatbot Model** prior to running the demo.
224
+
225
+ - Upload the commands.json file for processing
226
+ - Load the pickle data
227
+ - Create training data
228
+ - Build the model
229
+
230
+ """)
231
+
232
  # Explanation of code using st.markdown with bullet points
233
  st.markdown("""
234
  - This chatbot app offers the following options:
index.py CHANGED
@@ -1,6 +1,6 @@
1
  import streamlit as st
2
  from streamlit_option_menu import option_menu
3
- from chatbotlib import (train_chatbot, chatbot_demo)
4
 
5
  # displaying the icon image on streamlit app and set the page config.
6
  st.set_page_config(
@@ -40,4 +40,4 @@ match page_selection:
40
  train_chatbot.run_app()
41
 
42
  case "Demo the Chatbot":
43
- chatbot_demo.run_app()
 
1
  import streamlit as st
2
  from streamlit_option_menu import option_menu
3
+ from chatbotlib import (train_chatbot, demo_chatbot)
4
 
5
  # displaying the icon image on streamlit app and set the page config.
6
  st.set_page_config(
 
40
  train_chatbot.run_app()
41
 
42
  case "Demo the Chatbot":
43
+ demo_chatbot.run_app()