DreamStream-1 commited on
Commit
d1bd971
·
verified ·
1 Parent(s): c78efde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -25
app.py CHANGED
@@ -18,19 +18,19 @@ nltk.download('punkt')
18
  # Initialize the stemmer
19
  stemmer = LancasterStemmer()
20
 
21
- # Load intents.json
22
  try:
23
  with open("intents.json") as file:
24
  data = json.load(file)
25
  except FileNotFoundError:
26
- raise FileNotFoundError("Error: 'intents.json' file not found. Ensure it exists in the current directory.")
27
 
28
- # Load preprocessed data from pickle
29
  try:
30
  with open("data.pickle", "rb") as f:
31
  words, labels, training, output = pickle.load(f)
32
  except FileNotFoundError:
33
- raise FileNotFoundError("Error: 'data.pickle' file not found. Ensure it exists and matches the model.")
34
 
35
  # Build the model structure
36
  net = tflearn.input_data(shape=[None, len(training[0])])
@@ -39,12 +39,12 @@ net = tflearn.fully_connected(net, 8)
39
  net = tflearn.fully_connected(net, len(output[0]), activation="softmax")
40
  net = tflearn.regression(net)
41
 
42
- # Load the trained model
43
  model = tflearn.DNN(net)
44
  try:
45
  model.load("MentalHealthChatBotmodel.tflearn")
46
  except FileNotFoundError:
47
- raise FileNotFoundError("Error: Trained model file 'MentalHealthChatBotmodel.tflearn' not found.")
48
 
49
  # Function to process user input into a bag-of-words format
50
  def bag_of_words(s, words):
@@ -150,7 +150,7 @@ def provide_suggestions(emotion):
150
  return suggestions
151
 
152
  # Google Places API to get nearby wellness professionals
153
- api_key = "GOOGLE_API_KEY" # Replace with your API key
154
 
155
  def get_places_data(query, location, radius, api_key, next_page_token=None):
156
  url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
@@ -221,21 +221,3 @@ iface = gr.Interface(
221
  inputs=[
222
  gr.Textbox(label="Enter your message", placeholder="How are you feeling today?"),
223
  gr.Textbox(label="Enter your location (e.g., Hawaii, Oahu)", placeholder="Your location"),
224
- gr.State() # One state input
225
- ],
226
- outputs=[
227
- gr.Chatbot(label="Chat History"),
228
- gr.Textbox(label="Sentiment Analysis"),
229
- gr.Textbox(label="Detected Emotion"),
230
- gr.Dataframe(label="Suggestions & Resources"),
231
- gr.Dataframe(label="Nearby Wellness Professionals"), # Display results as a table
232
- gr.State() # One state output
233
- ],
234
- allow_flagging="never",
235
- title="Mental Wellbeing App with AI Assistance",
236
- description="This app provides a mental health chatbot, sentiment analysis, emotion detection, and wellness professional search functionality.",
237
- )
238
-
239
- # Launch Gradio interface
240
- if __name__ == "__main__":
241
- iface.launch(debug=True, share=True) # Set share=True to create a public link
 
18
  # Initialize the stemmer
19
  stemmer = LancasterStemmer()
20
 
21
+ # Load intents.json (directly in the app directory)
22
  try:
23
  with open("intents.json") as file:
24
  data = json.load(file)
25
  except FileNotFoundError:
26
+ raise FileNotFoundError("Error: 'intents.json' file not found in the app directory.")
27
 
28
+ # Load preprocessed data from pickle (directly in the app directory)
29
  try:
30
  with open("data.pickle", "rb") as f:
31
  words, labels, training, output = pickle.load(f)
32
  except FileNotFoundError:
33
+ raise FileNotFoundError("Error: 'data.pickle' file not found in the app directory.")
34
 
35
  # Build the model structure
36
  net = tflearn.input_data(shape=[None, len(training[0])])
 
39
  net = tflearn.fully_connected(net, len(output[0]), activation="softmax")
40
  net = tflearn.regression(net)
41
 
42
+ # Load the trained model (directly in the app directory)
43
  model = tflearn.DNN(net)
44
  try:
45
  model.load("MentalHealthChatBotmodel.tflearn")
46
  except FileNotFoundError:
47
+ raise FileNotFoundError("Error: Trained model file 'MentalHealthChatBotmodel.tflearn' not found in the app directory.")
48
 
49
  # Function to process user input into a bag-of-words format
50
  def bag_of_words(s, words):
 
150
  return suggestions
151
 
152
  # Google Places API to get nearby wellness professionals
153
+ api_key = "YOUR_GOOGLE_API_KEY" # Replace with your actual API key
154
 
155
  def get_places_data(query, location, radius, api_key, next_page_token=None):
156
  url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
 
221
  inputs=[
222
  gr.Textbox(label="Enter your message", placeholder="How are you feeling today?"),
223
  gr.Textbox(label="Enter your location (e.g., Hawaii, Oahu)", placeholder="Your location"),