DreamStream-1 commited on
Commit
fa97be4
·
verified ·
1 Parent(s): d7c7798

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -68
app.py CHANGED
@@ -14,6 +14,10 @@ from nltk.stem.lancaster import LancasterStemmer
14
  import os
15
  from functools import lru_cache
16
  import pandas as pd
 
 
 
 
17
 
18
  # Ensure necessary NLTK resources are downloaded
19
  nltk.download('punkt')
@@ -213,77 +217,22 @@ def generate_map(wellness_data):
213
 
214
  for place in wellness_data:
215
  name, address, lat, lon = place
216
- folium.Marker(
217
- location=[lat, lon],
218
- popup=f"<b>{name}</b><br>{address}",
219
- icon=folium.Icon(color='blue', icon='info-sign')
220
- ).add_to(m)
221
 
222
- # Save map as an HTML string
223
- map_html = m._repr_html_()
224
-
225
- return map_html
226
 
227
- # Gradio interface setup for user interaction
228
- def user_interface(message, location, history, api_key, words, labels, model):
229
- history, history = chat(message, history, words, labels, model)
230
-
231
- # Sentiment analysis
232
- inputs = tokenizer_sentiment(message, return_tensors="pt")
233
- outputs = model_sentiment(**inputs)
234
- sentiment = ["Negative", "Neutral", "Positive"][torch.argmax(outputs.logits, dim=1).item()]
235
-
236
- # Emotion detection
237
- emotion, resources, video_link = detect_emotion(message)
238
-
239
- # Get wellness professionals
240
- wellness_data = get_wellness_professionals(location, api_key)
241
-
242
- # Generate the map
243
- map_html = generate_map(wellness_data)
244
-
245
- # Create a DataFrame for the suggestions
246
- suggestions_df = pd.DataFrame(resources, columns=["Resource", "Link"])
247
-
248
- # Format the final output
249
- output = f"**Chat Response:** {history[-1][1]}\n\n"
250
- output += f"**Sentiment:** {sentiment}\n\n"
251
- output += f"**Detected Emotion:** {emotion}\n\n"
252
- output += "**Suggestions based on Emotion:**\n"
253
- for resource in resources:
254
- output += f"- [{resource[0]}]({resource[1]})\n"
255
- output += f"\n**Video Suggestion:** {video_link}\n\n"
256
- output += "**Wellness Professionals near you:**\n"
257
- output += map_html
258
-
259
- return output, history
260
 
261
- # Load intents and preprocessed data
262
- data = load_intents('intents.json')
263
- words, labels, training, output = load_preprocessed_data('data.pkl')
264
-
265
- # Build and load the model
266
- net = build_model(words, labels, training, output)
267
- model = load_model('model.tflearn', net)
268
 
269
  # Gradio interface
270
- iface = gr.Interface(
271
- fn=user_interface,
272
- inputs=[
273
- gr.inputs.Textbox(label="Message"),
274
- gr.inputs.Textbox(label="Location"),
275
- gr.State([]), # History
276
- gr.State(os.getenv("GOOGLE_API_KEY")), # API Key
277
- gr.State(words),
278
- gr.State(labels),
279
- gr.State(model)
280
- ],
281
- outputs=[
282
- gr.outputs.Markdown(label="Response"),
283
- gr.outputs.Chatbot(label="Chat History")
284
- ],
285
- title="Wellness Chatbot",
286
- description="A chatbot to provide wellness support and locate professionals near you."
287
- )
288
 
289
- iface.launch(debug=True)
 
14
  import os
15
  from functools import lru_cache
16
  import pandas as pd
17
+ import tensorflow as tf # Added to enable resource variables
18
+
19
+ # Enable resource variables in TensorFlow to avoid deprecated warnings
20
+ tf.compat.v1.enable_resource_variables()
21
 
22
  # Ensure necessary NLTK resources are downloaded
23
  nltk.download('punkt')
 
217
 
218
  for place in wellness_data:
219
  name, address, lat, lon = place
220
+ folium.Marker([lat, lon], popup=f"{name}\n{address}").add_to(m)
 
 
 
 
221
 
222
+ return m
 
 
 
223
 
224
+ # Initialize the necessary files
225
+ data = load_intents("intents.json")
226
+ words, labels, training, output = load_preprocessed_data("data.pickle")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
 
228
+ # Build the model
229
+ model = build_model(words, labels, training, output)
230
+ model = load_model("model.tflearn", model)
 
 
 
 
231
 
232
  # Gradio interface
233
+ def chatbot_interface(message, history):
234
+ return chat(message, history, words, labels, model)
235
+
236
+ # Example usage with Gradio UI
237
+ gr.Interface(fn=chatbot_interface, inputs=["text", "state"], outputs=["chatbot", "state"]).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
238