tahirsher commited on
Commit
a372e79
·
verified ·
1 Parent(s): 37ba1cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import nltk
2
- nltk.download('punkt') # Ensure 'punkt' resource is downloaded
3
  from nltk.stem.lancaster import LancasterStemmer
4
  import numpy as np
5
  import tflearn
@@ -9,19 +8,28 @@ import json
9
  import pickle
10
  import gradio as gr
11
 
 
 
 
 
 
 
12
  # Initialize the stemmer
13
  stemmer = LancasterStemmer()
14
 
15
  # Load intents.json
16
- with open("intents.json") as file:
17
- data = json.load(file)
 
 
 
18
 
19
  # Load preprocessed data from pickle
20
  try:
21
  with open("data.pickle", "rb") as f:
22
  words, labels, training, output = pickle.load(f)
23
  except FileNotFoundError:
24
- print("Error: data.pickle file not found. Ensure it exists and matches the model.")
25
 
26
  # Build the model structure
27
  net = tflearn.input_data(shape=[None, len(training[0])])
 
1
  import nltk
 
2
  from nltk.stem.lancaster import LancasterStemmer
3
  import numpy as np
4
  import tflearn
 
8
  import pickle
9
  import gradio as gr
10
 
11
+ # Ensure necessary NLTK resources are downloaded
12
+ try:
13
+ nltk.data.find('tokenizers/punkt')
14
+ except LookupError:
15
+ nltk.download('punkt')
16
+
17
  # Initialize the stemmer
18
  stemmer = LancasterStemmer()
19
 
20
  # Load intents.json
21
+ try:
22
+ with open("intents.json") as file:
23
+ data = json.load(file)
24
+ except FileNotFoundError:
25
+ raise FileNotFoundError("Error: 'intents.json' file not found. Ensure it exists in the current directory.")
26
 
27
  # Load preprocessed data from pickle
28
  try:
29
  with open("data.pickle", "rb") as f:
30
  words, labels, training, output = pickle.load(f)
31
  except FileNotFoundError:
32
+ raise FileNotFoundError("Error: 'data.pickle' file not found. Ensure it exists and matches the model.")
33
 
34
  # Build the model structure
35
  net = tflearn.input_data(shape=[None, len(training[0])])